[SalesForce] Convert SQL query into SOQL query

I've been trying to figure out how to turn this SQL query into a SOQL query. Every time I think I am getting better with SOQL something comes along and erases that thought. Account is the parent object and has a Master-Detail relationship with Merchant Location. Any help is appreciated. Yes I have studied all of the Salesforce documentation on SOQL and it has been helpful in my learning. I can't seem to get my mind wrapped around this query.

select mo.ISOOffice__Merchant_Location__c as Main_Location_ID from Account a 

left outer join ISOOffice__Merchant_Opportunity__c mo on a.Id = mo.ISOOffice__Account__c 
where a.name = 'Company Name' 

and mo.ISOOffice__Opportunity_Type__c = 'New Merchant'

Best Answer

Also you can directly query in child object using relationship fields,

[select ISOOffice__Merchant_Location__c,Account__r.Name 
 from ISOOffice__Merchant_Opportunity__c where 
 ISOOffice__Opportunity_Type__c = 'New Merchant' AND 
 Account__r.Name = 'Goodwill of Southwestern Pennsylvania']

You need to prefix ISOOffice__Merchant_Location__c with Account__r, if this field is in account.

Related Topic