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

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

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.