Reply
Contributor
GowthamSen
Posts: 4

How to create SOQL for recursive relationship on Contact ?

 we have table "Contact". There are fields Id, Name and Reports To fields and so on.

The "Reports To" field is lookup to Contact.

Here, I would like to find Contact --> Contact's Supervisor ----> Contacts Supervisor's Supervirsor ---> and so on.

 

Can you please explain how to define this relationship using SOQL?

 

Best Regards
Gowtham

Regular Contributor
bvramkumar
Posts: 63

Re: How to create SOQL for recursive relationship on Contact ?

You can not directly achieve the entire hierarchy of contacts with single SOQL. you will need to write a bit of Apex.

Contributor
GowthamSen
Posts: 4

Re: How to create SOQL for recursive relationship on Contact ?

Thanks a lot for responding to my message.

 

Could you please guide me on how to write Apex code.

 

I am new to Saleforce. Please help me here.

 

Best Regards

Gowtham

Contributor
ddsouza
Posts: 6

Re: How to create SOQL for recursive relationship on Contact ?

Here is a link to the official apex code developer guide : http://www.salesforce.com/us/developer/docs/apexcode/index.htm

It has useful information and examples to get you started.