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
Nikolay Kolev 19Nikolay Kolev 19 

Spring '18 no longer supporting Order by Distance and geolocation type

I just noticed that one of my queries is no longer working in my sandbox after the Spring '18 has been applied to that sandbox.

In particular this is the error SF is returning:
[object Object]: 'mi') < 55 ORDER BY DISTANCE(someObject__c.Geo_Location__c, GEOLOCATION(33.4589034 ^ ERROR at Row:1:Column:199 field 'Geo_Location__c' can not be sorted in a query call

The WHERE clause in my query breaks it and here's what that where clause looks like:
DISTANCE(someObject__c.Geo_Location__c, GEOLOCATION(33.4589034, -112.0889634), 'mi') < 55 ORDER BY DISTANCE(someObject__c.Geo_Location__c, GEOLOCATION(33.4589034, -112.0889634), 'mi')

The Geo_Location__c field is a geolocation type field. This is still working in Winter '18.
Do you know why this change was applied and if there's a workaround this?

Also if you look at SF's documentation they provide a very similar example in their code: https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_geolocate.htm
NagendraNagendra (Salesforce Developers) 
Hi Nikolay,

What instance is your sandbox? I have the same problem in one client's sandbox (CS9) but not in another client's sandbox (CS17) even though both are at Spring 18. In the CS9 sandbox, I even created another Geolocation field in a different object but the ORDER BY DISTANCE fails to compile for that object as well.

I have opened a case with Salesforce premier support, will update here when I have more info.

Thanks,
Nagendra