3

i am trying to find nearest stores and their longitude and latitude based on customer location (lon,lat) and populate in Google map. Here is a sample query would work in MySQL. Would this same query work in Salesforce? Do we have Radians function or equivalent function for Radians in salesforce? Moreover, is this possible to frame a query like this?

 SELECT
`id`,
`name`,
ACOS( SIN( RADIANS( `latitude` ) ) * SIN( RADIANS( $fLat ) ) + COS( RADIANS( `latitude` ) )
* COS( RADIANS( $fLat )) * COS( RADIANS( `longitude` ) - RADIANS( $fLon )) ) * 6380 AS `distance`
FROM `stations`
WHERE
ACOS( SIN( RADIANS( `latitude` ) ) * SIN( RADIANS( $fLat ) ) + COS( RADIANS( `latitude` ) )
* COS( RADIANS( $fLat )) * COS( RADIANS( `longitude` ) - RADIANS( $fLon )) ) * 6380 < 10
ORDER BY `distance`

Any ideas?

Thanks, Baskaran

1

1 Answer 1

9

No, there is no radians function available directly in SOQL. However The new release of SOQL includes geolocation cababilities, you do not need to calculate distance yourself. Try something like:

ORDER BY Clause Sort records by distance using a distance condition in the ORDER BY clause. For example:

SELECT Name, StreetAddress_c FROM Warehouse_c WHERE DISTANCE(Location_c, GEOLOCATION(37.775,-122.418), 'mi') < 20 ORDER BY DISTANCE(Location_c, GEOLOCATION(37.775,-122.418), 'mi') LIMIT 10

https://www.salesforce.com/us/developer/docs/dbcom_soql_sosl/index_Left.htm#CSHID=sforce_api_calls_soql_geolocate.htm|StartTopic=Content%2Fsforce_api_calls_soql_geolocate.htm|SkinName=webhelp

You must log in to answer this question.

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