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
sam_Adminsam_Admin 

Help in Query

Hi All,

    How to use more than one zip code in query , iam getting error.

 

Select Id, PostalCode FROM Lead WHERE IsConverted = false AND PostalCode like ('%32814%' ,'%32816%','%32819%')

SabrentSabrent

Try the keyword IN instead of LIKE

 

Select Id, PostalCode FROM Lead WHERE IsConverted = false AND PostalCode IN ('%32814%' ,'%32816%','%32819%')

sam_Adminsam_Admin

It doesn't give me any results if i use IN

SabrentSabrent

Oh my bad! that's because of %

 

Can you try INCLUDES

I am not sure if it will work as it applies only to multiselect picklists but give it a try. 

sam_Adminsam_Admin

sry includes doesn't work i tried this and it works but am trying to use postal code everytime, i don't know how to make more simple

 

Select Id, PostalCode FROM Lead WHERE IsConverted = false AND (PostalCode like '%20814%' or PostalCode like '%20815%' )

Andy BoettcherAndy Boettcher

Why are you wildcarding the zip codes?  Aren't they pretty static?

sam_Adminsam_Admin

well some records might have 9 digit and some might have only 5 so iam specifically trying to find out all records for these existing zip codes

sfdcfoxsfdcfox

For performance and logical reasons, you should ditch the leading wildcard. From a performance standpoint, salesforce has to try to match the entire string within the entire field, instead of just checking from left to right at the beginning. And, of course, you could receive false positives, such as 132814267 (a hypothetical zip code '13281' with a +4 and no hyphen). Don't assume it can't happen, because users are prone to dropping punctuation if they get lazy.

 

Edit: I should also note that IN does not use wildcards. You'd use LIKE for that comparison.

sam_Adminsam_Admin

You are totally right but am fine with 132814267, all i need is the records for the zip code that contains 13281as long as it is 5 or 9 digit

BussBuss

Hi Sam,

 

you can use SOSL query, which may help to get all the records starting with 32121.

 

Rgds,

Buss

Nilesh ManeNilesh Mane

Make a String List of Postal codes and use IN clause in Query.

 

For Example :  

List<String> PcodeList = new List<String>();

PcodeList .add(32814);

PcodeList .add(32816);

PcodeList .add(32819);

..........

..................[ Select Id, PostalCode FROM Lead WHERE IsConverted = false AND PostalCode IN :PcodeList ];