1

Can we use distance field on a SOSL? Below query returns an error

FIND {CA} IN ALL FIELDS RETURNING Contact (id, CMFSH__Resume_Id__c, name,email,phone,mailingstreet,mailingCity,mailingState,mailingCountry,mailingpostalcode,mailingAddress,distance(MailingAddress, geolocation(37.77829660,-122.41720310), 'mi') dist  LIMIT 1000 ) 

mailingAddress,distance(MailingAddress, geolocation(37.77829660,-122.41720310) ^ ERROR at Row:1:Column:195 Malformed search token: ','

While using the same on SOQL runs fine

SELECT id,name,distance(MailingAddress, geolocation(37.77829660,-122.41720310), 'mi') dist from contact
  • The documentation doesn't mention anything about SOSL support, so I don't think it's actually possible. – sfdcfox Nov 26 '18 at 11:11
  • Thought so.. just wanted to confirm :) – Prady Nov 26 '18 at 11:18
2

The SOQL and SOSL Reference makes mention multiple times of how this functionality is specific to SOQL:

Location-Based SOQL Queries

Location-based SOQL queries let you compare and query location values stored in Salesforce.


How SOQL Treats Null Location Values


How SOQL Calculates and Compares Distances


Location-Based SOQL Query Considerations

Location-based queries are supported in SOQL in Apex and in the SOAP and REST APIs. Keep in mind these considerations.

Given the wording and care taken to specify this functionality as supported in SOQL, it certainly seems to indicate it is the only place where it is supported.

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.