Skip to main content
edited tags; edited title; Post Made Community Wiki
Link
Adrian Larson
  • 151.3k
  • 38
  • 247
  • 431

SOQL for Lookup How do I find the child relationship name?

un-abbreviated 'LKP' to 'lookup'
Source Link
Derek F
  • 64.1k
  • 15
  • 55
  • 104

SOQL for LKPLookup relationship

I'm using a SOQL to query the LKPlookup relationships.

Primary Object: Opportunity

Secondary Object: Purchase__c.

From purchase__c we have a LKPlookup to opportunity.

Field Name: Opportunity__c

Child Relationship Name: Purchases2

SOQL query:

for (Opportunity opp : [select Id, Name, (select id from Purchases2__r where Count__c>0) from Opportunity where Id IN :oppIds]) 

whats wrong with my query? getting error below:

If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name.

If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name.

SOQL for LKP relationship

I'm using a SOQL to query the LKP relationships.

Primary Object: Opportunity

Secondary Object: Purchase__c.

From purchase__c we have a LKP to opportunity.

Field Name: Opportunity__c

Child Relationship Name: Purchases2

SOQL query:

for (Opportunity opp : [select Id, Name, (select id from Purchases2__r where Count__c>0) from Opportunity where Id IN :oppIds]) 

whats wrong with my query? getting error below:

If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name.

SOQL for Lookup relationship

I'm using a SOQL to query the lookup relationships.

Primary Object: Opportunity

Secondary Object: Purchase__c.

From purchase__c we have a lookup to opportunity.

Field Name: Opportunity__c

Child Relationship Name: Purchases2

SOQL query:

for (Opportunity opp : [select Id, Name, (select id from Purchases2__r where Count__c>0) from Opportunity where Id IN :oppIds]) 

whats wrong with my query? getting error below:

If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name.

Source Link

SOQL for LKP relationship

I'm using a SOQL to query the LKP relationships.

Primary Object: Opportunity

Secondary Object: Purchase__c.

From purchase__c we have a LKP to opportunity.

Field Name: Opportunity__c

Child Relationship Name: Purchases2

SOQL query:

for (Opportunity opp : [select Id, Name, (select id from Purchases2__r where Count__c>0) from Opportunity where Id IN :oppIds]) 

whats wrong with my query? getting error below:

If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name.