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

How to use an Array in the Query

Hello All,


I am writing a Java program that gets information from a database and will upload that information into Salesforce.


I have placed the Ids of the Accounts from the database into an Array and I want to query the Accounts object in Salesforce to get me the Account objects from Salesforce where there is a match found in the Array of Ids.


I have a query that reads something like this:

String[] accIds = new String[x];

binding.query("SELECT Id, Name, databaseId FROM Account WHERE databaseId IN " + accIds);


I am getting stuck with the query as I'm not 100% sure how to do it properly and I cannot find any information on how this should be done.


Any help is highly appreciated.


Thanks in advance!


Best Answer chosen by Admin (Salesforce Developers) 

You will have to enclose each ID in a single quote and have a paranthesis around them.  Check out the syntax for IN here.