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
Chad MoutesChad Moutes 

GEO Location Formula Help

So I have a custom object called Airport which is a lookup to the Account object, and it literally is just all of the Airports in America. And what i would like to do is create a formula field on the Account that Displays the closest Airport to that address. Does anyone know how this is possible? I would like to be able to just compare them by city and state.

So for instance lets say that the account is for Quicken Loans Arena in Ohio, then I want it to take Cleveland, Ohio and find the airport that is the closest to that location which would be Cleveland-Hopkins International. I can explain this alittle better if I'm not being clear enough.

Any Ideas?
Hello Chad,

I am not sure if you can do a formula field for your requirement. You need to get it via a trigger or via code, because you need to compare all airports with account record to get the closest one.

So if you have an account record, that has an address in Greater Boston area, it needs to compare all the airports to get the closest one. so basically if you write a SOQL quey it would be

Assuming you have adress fields,

List<Airport__c> airports = [Select id, Name, AirportAddress__c from Airport__c ORDER BY DISTANCE(acct.BillingAddress, AirportAddress__c) LIMIT 1];
Gives the closest ones.
Chad MoutesChad Moutes
Hey logontokartik,

I know that it would be much easier to accomplish this feature with Apex. But the only issue is that the client I am trying to do this for is on proffessional edition and doesnt have a snadbox.