SOQL and SOSL statements in Apex can
reference Apex code variables and expressions if they’re preceded by a
colon (:). This use of a local code variable within a SOQL or SOSL
statement is called a bind. The Apex parser first evaluates the local
variable in code context before executing the SOQL or SOSL statement.
Double myLatitude = 10;
Double myLongitude = 10;
List accountList = [SELECT Id, Name, BillingLatitude, BillingLongitude
FROM Account
WHERE DISTANCE(My_Location_Field__c, GEOLOCATION(:myLatitude, :myLongitude), 'mi') < 10];
Location myLocation = Location.newInstance(10, 10);
Double myDistance = 100;
List accountList = [SELECT Id, Name, BillingLatitude, BillingLongitude
FROM Account
WHERE DISTANCE(My_Location_Field__c, :myLocation, 'mi') < :myDistance];
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment