List<String> cityList = Label.cityNames.split(',');
    String SOQL = 'Select id, name from Account where city IN:cityList'


Could you please correct the above query to bind the list into SOQL.

The above dynamic SOQL is working fine if I pass new List<String> {'A','B','C'}


There is no standard field name called "City", it should be BillingCity or ShippingCity. Check with below query and use Database.Query instead Database.ExecuteQuery

List<String> cityList = Label.cityNames.split(',');
system.debug('--- cityList ---'+cityList);
String strQuery = 'Select id, name from Account where Billingcity IN:cityList';
List<Account> lstAccount = Database.query(strQuery);
system.debug('--- lstAccount ---'+lstAccount);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.