1

I am using what3words (http://what3words.com) to save locations in Salesforce, by simply copying the w3w address from their app and pasting it into Salesforce using the mobile app.

I want to then convert the what3words address to lat/long using their API, which is in the form of a URL

http://api.what3words.com/w3w?key=YOURAPIKEY&string=word1.word2.word3

Is there a way to write code in Salesforce to do this automatically as my w3w address field gets populated?

I'm fairly experienced with Apex coding, but no experience with API's. I'm having a hard time searching for a good example/tutorial because every time I search for anything with "salesforce" and "api" in the search term, I only get the SF developer documentation results.

If anyone can point me in the direction of a good example/tutorial, that would be much appreciated.

Thanks

1

What you need to look at is making a REST callout using...ready...Apex!

Yay...you already know it!

There are just a few things to note:

  1. If you want this to happen upon save of this record, you will need to do it during a trigger.
  2. If you are making a callout during a trigger, it must be annotated @future(callout=true)
  3. You will need to be choosey as to whether to do this when you are doing bulk processing, as you only get a few callouts per transaction.
  4. You will need to update the same record that was just saved...so make sure to prevent a recursive trigger execution (i.e. you save again, because you saved, because you saved before, etc...ad nauseum...ad fragor...) using a static variable.

There are a lot of articles on REST callouts from triggers including this question here on SFSE. There is also this video on REST callouts (to StackExchange, ironically) by Matt Kaufman from Dreamforce last year.

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.