-3

how to feed values from SOQL to the API, that is feed zip code to the API. And calculate the distance between the two zip code.

0

If your question is regarding querying zip code from any of the two records in Salesforce to find the distance between them using google api, then below is the code snippet:

List<Account> lstAccounts = [SELECT ShippingPostalCode FROM Account WHERE Name = 'Test1' OR Name = 'Test'];

Http http = new Http();
HttpRequest req = new HttpRequest();
HttpResponse resp;
req.setMethod('GET');
req.setEndpoint('http://maps.googleapis.com/maps/api/distancematrix/json?origins='+lstAccounts[0].ShippingPostalCode+'&destinations='+lstAccounts[1].ShippingPostalCode+'&language=en-EN&sensor=false');
resp = http.send(req);
System.debug('------resp-----------'+resp.getBody());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.