I'm working on a travel price list function where I need to check if a customer inquiry matches a price list entry.

The price list entry has a destination position (geolocation) and a radius (number), the radius specifies how many kilometers from the destination position the price list entry is valid for.

The inquiry has a destination position (geolocation), and my task is to find the price list entry that this inquiry position fits into by checking if the destination position goes into any price list area (position with radius).

My SOQL goes like this:

select Id,Name 
from Fixed_price__c 
where distance(Destination_position__c, geolocation(59.29751613,18.08904094), 'km') < Destination_radius__c

The geolocation lat and long values are the inquiry coordinates, they are inserted to the query by apex code.

This SOQL gets a parsing error when I use Destination_radius__c instead of a fixed value, it seems that I cannot compare a distance with the field Destination_radius__c? I have Googled around and cannot find anything about this.

The other solution would be to select all Fixed_price__c rows and do a comparison in apex of course, but a single query like the one above would be nicer.

Is this a limitation in the SOQL, or is there any workaround?

  • Yes this is an inherent limitation of SOQL.
    – Adrian Larson
    Commented May 7, 2015 at 12:02

1 Answer 1


Create a number formula Dist_minus_radius__c with contents

distance(Destination_position__c, geolocation(59.29751613,18.08904094), 'km') - Destination_radius__c

In the SOQL query, do:

where Dist_minus_radius__c < 0
  • Thanks for your help, but the GPS coordinates will vary and will be inserted dynamically with apex so I can't put them into a formula.
    – Andreas
    Commented May 25, 2015 at 11:23

You must log in to answer this question.

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