0

Is there any way to get Salesforce to return related lists when I lookup an object using their API?

Right now I am searching Contact objects for an email address and I am able to get back all the single fields (both standard fields and fields we've added) but I don't get any of the related lists (either standard or custom).

I initially was going to Contact, getting the ID and then I would try and do another query on the related list object, but I think because this is a master-detail relationship you can't search on it?

1 Answer 1

1

You can use a inner query to achive this.

Salesforce SOQL Subquery and Custom Objects with Apex

The sample example will be like,

List<Account> accountList = [Select Id, Name,(Select id from AccountContactRoles), (Select Id from Contacts)   from Account where Id=: 'some id'];

System.debug('###'+accountList);

for(Account obj : accountList){
    System.debug(':::'+obj.Contacts);
    System.debug(':::'+obj.AccountContactRoles);
}

You can verify the Relationship name using Workbench --> Info --> Standard and Custom Object -> Select and Object for which Relationship to be verified

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .