function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
pearlbearpearlbear 

SOQL query help on custom object

Hi there,

 

I'm trying to do a child to parent query from a standard to a custom object. 

 

I've tried: 

SELECT Contact.npo02__Household__c.Household_Salutation_1__c FROM Contact WHERE Contact.Id = :conID

 

But it's throwing this error:

 

 Didn't understand relationship 'npo02__Household__c' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name.

 

I have also tried:

SELECT npo02__Contacts__r.Household_Salutation_1__c FROM Contact WHERE Contact.Id = :conID

 

And I get this error: 

Didn't understand relationship 'npo02__Contacts__r' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name.

 

So I'm stuck. Suggestions?

Best Answer chosen by Admin (Salesforce Developers) 
forecast_is_cloudyforecast_is_cloudy

You're not using the correct SOQL syntax for parent-child relationships. Via the Setup menu, look at the API Name for the 'Household' custom lookup field on the Contact object. Assuming that it's 'Household__c', your SOQL should be:

 

SELECT Household__r.Household_Salutation_1__c FROM Contact WHERE Contact.Id = :conID

 

FYI - You can also determine the correct API name for the 'Household' relationship field via the Schema Explorer in Eclipse.

All Answers

forecast_is_cloudyforecast_is_cloudy

You're not using the correct SOQL syntax for parent-child relationships. Via the Setup menu, look at the API Name for the 'Household' custom lookup field on the Contact object. Assuming that it's 'Household__c', your SOQL should be:

 

SELECT Household__r.Household_Salutation_1__c FROM Contact WHERE Contact.Id = :conID

 

FYI - You can also determine the correct API name for the 'Household' relationship field via the Schema Explorer in Eclipse.

This was selected as the best answer
pearlbearpearlbear

Actually, np02__Contact__r is the custom lookup field on the Contact object.

Alok_NagarroAlok_Nagarro

Hi,

 

your query should be like...

 

SELECT Contact.npo02__Household__r.Household_Salutation_1

__c FROM Contact WHERE Contact.Id = :conID

 

 

Actually ,second time you tried npo02__Household__r, but this relationship exist with contact object so you have to write

full relation (Contact.npo02__Household__r) to access parent record.

 

 

Thanks,

pearlbearpearlbear

Actually, I got it - I used the wrong relationship - I was using the relationship in the Household object rather than the one in the contact object. Once i used that, I was all set.