I have custom field in the Opportunity object that is a Lookup and maps the Opportunity object to the User object. I'm trying to write a query that retrieves fields from the Opportunity, and also includes the Email field from the User based on a WHERE clause of AccountId = 'somerandomaccountid'. Apologies if this is confusing, but can anyone help me out with understand cross-object queries with custom fields?
[SELECT Custom_Field__r.Email, ... FROM Opportunity WHERE AccountId = '..']
assuming the customfield is named Custom_Field__c
If the custom lookup field is named
Foo__c and points at some object (standard or custom) the relationship name from object to its parent is
If it is a standard object with a lookup to another standard object and the lookup field is named
FooId, then the relationship name is
You can lookup the relationship names in any schema browser (such as Workbench) by going to the child object and inspecting the lookup field