0

My php client connects to salesforce using their SOAP API ( partner.wsdl ). After getting a list of Accounts, I also want a list of all the Contracts for each Account. Since SOQL doesn't allow join statements, the only way I see is to first get a list of ALL the Contracts, then manually filter down to the Contracts associated with a particular Account.

This question is similar, but no answer presents a better solution.

Community
  • 1
  • 1
NoodleFolk
  • 1,949
  • 1
  • 15
  • 24

1 Answers1

1

you have multiple options, first you can get all contacts ascoicated with any account with

select id, name ... from contact where accountId != null

if you have a one or a small numer of accounts that you want contacts for you can do

select id,name from contact where accountId in ('id1','id2','id3')

or, if you want to get contact data when you get account data, you can do

select id,name, (select id,name from contacts) from account

or, if you have a complex account query and you want just the contacts for that in a separate query, you can do

select id,name from contact where accountId in (select id from account where ....)
superfell
  • 18,780
  • 4
  • 59
  • 81
  • Thanks for your reply. I'm actually querying contRact from account. I've never seen syntax like this `select id, name, (select id, accountid from contract) from account` before. – NoodleFolk Jun 10 '13 at 17:16