fflib-apex-common
fflib-apex-common copied to clipboard
QueryFactory addOrdering - Support for Distance
At this time, it appears I have no way of creating a query that does the following:
SELECT Id, Name, MailingLatitude, MailingLongitude FROM Contact ORDER BY DISTANCE(MailingAddress, GEOLOCATION(40.7657, -73.9899), 'mi') ASC
Because DISTANCE is not a field, there is no way to call addOrdering to support the above. If this is possible, can someone help me out? If not, I'd like to propose an enhancement.
Thanks!
@tmowbrey Create a formula field if you are going to use the same geolcation coordinates
That's easy enough when managing your own org, but I'm using this for a managed package where I don't know the object that I'm querying before hand. I'm asking the end user to provide the compound address or geolocation fields as part of setup. I'd prefer that we determine if we can add an additional method to support distance and geolocation adds to the query factory, if possible.
So we want a generic enhancement to support soql functions in select/where/order by clauses. Sounds useful to me. Marked as an enhancement request.