With a Perl script and one API query I read about 3000 accounts (looping through results with nextUrl). SOQL query string is like SELECT ID, Name FROM Account WHERE ...
What is the best way to get a list of all related contacts? My First idea was to get a string with all Account Ids and use it in query: SELECT Id, EMail FROM Contact WHERE AccountId IN ( $AccountIdString )
But then the resulting query string will be too long (max. 4000 characters in WHERE). So If have to use multiple queries with maybe 500 AccountIds.
Is there a better way which works with only one query?