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

Query Contact with where clause


Im trying to query tax id's from salesforce using a LinkedList of Strings.
Im am not performing it properly in batch/bulk format, so I am going over
my allotted requests for the day.

Can any help me out with this query?

private static LinkedList<String> queryContacts(LinkedList<String> ssns,SoapBindingStub binding){
  LinkedList<String> taxid = new LinkedList<String>();
  QueryResult qr = null;
   int count = 0; 
   for(Iterator<String> it = ssns.iterator();it.hasNext();){
   String txid =;
   String query = "select TaxID__c from Contact where TaxID__c="; 
   try {

    qr = binding.query(query);
    if (qr.getSize() != 0) {
              for(int i =0;i<qr.getSize();i++){
              SObject account = qr.getRecords()[i];
              System.out.println("Retrieved account AccountNumber__c: " +getFieldValue(account.get_any(), "TaxID__c"));

             } else {
              System.out.println("Hmm...\nDid not find the account, that's strange.");
             //System.out.println("\nQuery succesfully executed.");
         } catch (ApiFault af) {
                     .println("\nFailed to execute query succesfully, error message was: \n"
                             + af.getExceptionMessage());
         } catch (Exception ex) {
                     .println("\nFailed to execute query succesfully, error message was: \n"
                             + ex.getMessage());
   return taxid;


build an in query, e.g. select ... from contact where taxId__c in ( 'taxID1', 'taxID2', 'taxID3', .... )

read the results into a map to work out which ones you got and which ones you didn't.
Just out of curiosity, how do you handle the:
"Query string cannot be more than 1000 characters"?

Since i have so many items to query for.
its 10000 not 1000, but keep adding them til your string is just under the limit, run that query, then do it again, and so on until you're done.