I tried doing this..

DISTANCE(Fire_Station__r.Location__c, GEOLOCATION(xx.xxxxx, xx.xxxxx)

but it's failing.

Can I compute distance with a parent location field?

  • What exception is thrown?
    – EvAzi
    Commented May 25, 2017 at 16:54

1 Answer 1


This formula field on Contact object works fine where it is referring Account's Location field.

Moreover, Distance formula takes 3 arguments including unit, which is missing at your code.

DISTANCE( Account.Location__c, GEOLOCATION(37.775,-122.418), 'km')


Also, following SOQL query works well

SELECT Id, Name 
     FROM Contact
     WHERE DISTANCE(Account.Main_Office__c, GEOLOCATION(37.775,-122.418), 'km') > 20

Refer Location and Distance Variables Allowed in SOQL and SOSL Queries in Apex - release notes

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .