+ Start a Discussion
lopezclopezc 

Relationship query

Hi

 

I would like to retrieve information from the parent of the Account linked to a contact. The query is based on the object Contacts, is it possible to do it?

 

Something like:

 

Select Account.ParentId.FieldName__c from Contact 

Best Answer chosen by Admin (Salesforce Developers) 
incuGuSincuGuS

If they are not Child relationships you can access as many relationships as you want.

 

For example :

 

 

Select Account.Parent.Name From Contact

 

 

I think this is what you needed, let me know how it works out ,

Gaston.

All Answers

Ispita_NavatarIspita_Navatar

In case you want to access the field of Account object say FirstName, LastName then rephrase your query as given below:-

 

Select c.Account.FirstName, c.Account.LastName from Contact c

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.

lopezclopezc

No it doesn't. I want to go 2 levels above, so to the parent of the Account that it is the parent of the Contact

 

Something like "Select c.Account.Account.FirstName from Contact c"  but that it doesn't work

incuGuSincuGuS

If they are not Child relationships you can access as many relationships as you want.

 

For example :

 

 

Select Account.Parent.Name From Contact

 

 

I think this is what you needed, let me know how it works out ,

Gaston.

This was selected as the best answer
SuperfellSuperfell

because there's no relationship called account on account, its called parent. (you should get confortable with one of the schema explorer tools).

 

select account.parent.name from contact