function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
LacevedoLacevedo 

How to join to TAbles with Sforce API

I want to join two relational tables with its respective relation ids.

for example, I want to join Account and Contact table with

with Account.Id = Contact.AccountId.

 

 

DevAngelDevAngel

Hi Lacevedo,

Create a dataset.  Add 2 datatables and make sure that the id of the master is in the master and in the child.  Set the primary key on the master to be the id of the master.  Create a Relationship object using the primary key of the master and the foriegn key of the child. Voila, you have joined the 2 tables in the dataset.

playplayplayplay

My question is similar to this. What I need to do is to download some contacts using some query like:

select firstname, lastname from contact c

inner join account a on a.accountId = c.accountId

where a.AccountTerritory = 'United States'

Can I do this with SOQL? Or there are other ways I can retrieve contacts by criteria in related tables?

Thanks.

 

SuperfellSuperfell
You can't do this with SOQL today in a single call. You'd have to run the first query to get all the account Ids, then run the 2nd query to get all the contacts for those account Ids.