0

I am unable to get records from objects which has relationship like the following.

We already knew that Account and contact have relationship where as Account is parent. I created a child for contact and the object name is Product. There is no any relationship between Account and Product.

But now, i want to get records of Contact and Account from Product which means Product is return type.

SELECT id, name, Product__c.contact__r.lastname, Product__c.contact__r.accountId from Product__c

By using the Above query, i can able to get product id and name, contact name and account id.

But How to get account name and phone(remaining fields) along with the Account id.

Please help me in this....

1

Try the below SOQL you don't need to put the Product__c.Contact__r.lastname just put it as Contact__r.lastName OR Contact.Lastname and is Contact__c your custom object I think it should be the standard Object so try both the SOQL given below.

SELECT id, name, Contact__r.lastname, Contact__r.account.id,Contact__r.account.Name,Contact__r.account.Phone from Product__c

OR

SELECT id, name, Contact.lastname, Contact.account.id, Contact__r.account.Name,Contact__r.account.Phone from Product__c
| improve this answer | |
  • Its my fault. i didn't explain my question completely. Please see my updated question. and please respond to it. – user40339 Jan 9 '17 at 7:02
  • check the updated answer – RCS Jan 9 '17 at 7:05
  • Before posting this question I also tried with Contact__r.account.Name, but its showing output like [object Object]. – user40339 Jan 9 '17 at 7:11
  • Where are you executing this SOQL? – RCS Jan 9 '17 at 7:13
  • So that's fine it's a limitation of dev console. You can try the same SOQL query on Workbench – RCS Jan 9 '17 at 7:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy