+ Start a Discussion

Regarding SOQL Performance

Hi Team,


We need some technical help with addressing GEOLOCATION and distance based SOQL queries in one of our app. Currently the response is delayed for users. We are trying to explore our options to enhance the user experience.


Below is SOQL query in @RemoteAction Method in Controller Class, it is taking longer time to fetch the Accounts in full copy sandbox.


string q='SELECT BillingCountry,BillingCity,BillingStreet,Latitude__c, Longitude__c, Geolocation__latitude__s,Geolocation__longitude__s,BillingPostalCode,BillingState,'+valueField+','+EmployeeField+','+NameField+' FROM '+sObjVal+' WHERE '+NameField+' LIKE \'%'+param+'%\' AND geolocation__longitude__s!=null ';
             q+='AND DISTANCE(Geolocation__c,GEOLOCATION('+lat+','+longt+'),\'mi\')<50 ORDER BY DISTANCE(Geolocation__c,GEOLOCATION('+lat+','+longt+'),\'mi\') LIMIT 50'; 


Geolocation__c : This field stores the latitude and longitude of an account

Lat, longt: This variables store the latitude and longitude of current location.


Please let us know if we have any better approach to get Distance based search results.





If your query has like clause, it will check each and every record, is it possible to query without using like clause




Thank you for replying.


The problem is not due to "LIKE" operator in query. The issue is due to using of GEOLOCATION and DISTNACE functions.

Do we have any workaround to improve the query performance.