1

I have accounts with billingcities.

I have a query like below,

select id , billingcity from account where billingcity like%atl%

If i want to search on multiple cities, how can I do this? will comma seperated values work in like.

select id, billingcity from account where billingcity like%atl,por,bos%

Please help

2

You can use a Collection of type String to find values using like:

String[] cities = 'atl%,por%,bos%'.split(',');
Account[] accounts = [select id, billingcity from account where billingcity like :cities];

Otherwise, you'd have to use the far more tedious method of building a query string:

select id, billingcity from account where billingcity like 'atl%' or billingcity like 'por%' or billingcity like 'bos%'
  • Thank you sfdcfox, it worked, i marked as best answer as I saw yours first. and thank you @santanu – Anurag Jun 16 '16 at 19:46
1

You can use like this:

Set<String> billingCityNames = new Set<String>{'%atl%', 'por%', 'bos%'};
select id, billingcity from account where billingcity like :billingCityNames

or you can use:

select id, billingcity from account where billingcity like '%atl' OR billingcity like '%por%' OR billingcity like 'bos%

Using of bind variable is more preferable in terms of secure coding practice.

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.