You need to sign in to do that
Don't have an account?
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?
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
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.
Actually, np02__Contact__r is the custom lookup field on the Contact object.
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,
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.