Here's what I'm trying to do:
- Search and find a list of contact records with zip codes.
- Filter those records using zip codes that are in 5 km radius.
I'm unable to perform the 2nd point.
Is there any document which could help me in this?
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.Sign up to join this community
SOQL supports Location-Based Queries. You can retrieve records with locations within or outside of a certain radius with DISTANCE conditions in the WHERE clause of the query.
You can combine Distance and ZIP Code list to get the desired contacts.
Your SOQL should look this:
List<Contact> contactList = [Select Id, FirstName, LastName From Contact Where Distance(MailingAddress,GeoLocation(:latitude, :longitude),'km') < 5 AND MailingPostalCode IN :zipCodeList];