You need to sign in to do that
Don't have an account?

Google geocoding API
I want to hit google's geocoding api from an @future class on a trigger so I can add lat and lon to records as they change. I have a couple questions:
Steve
- If I want to hit the rest interface for google's service, I need to supply an api key. Do I need to do anything special to get that key to work from salesforce.com servers? It asks me to identify the calling domain--should that be salesforce.com?
- The API will respond to one call every 2 seconds, equating to 50,000 calls a day. What's the best way to deal with that limiter in an apex class? I couldn't find a sleep function.
Steve
2. Could possibly try just looping till the service doesn't return an error. It's dirty but could work. Other than that look into alternate geocoding services?
- There is no sleep function in Apex--I understand why they don't want my processes hanging out on their sever--so you can't time something like this from a class.
- Google gives you a 620 error if you hit the server too soon after your last hit. If you get this error, you could flag the record to be geocoded at a later date, probably from a VisualForce page because...
- You can do timing from a VisualForce page with the Action Poller control, so you could queue up 100 records and geocode them every 2 seconds
- Like Luke, Ron hasn't had any problems geocoding from salesforce.com servers. We'll see what happens as more and more folks hit google from salesforce ip addresses
SteveIf you're willing to pay a bit you can easily find a service that will allow unlimited lookups and get around all of the problems in one go.
Given the constraint of working with a free service like google, how do you automate this process:
1. If you put a trigger with @future, the trigger can handle no more than batch of 10 contacts, since callout limit is 10 for Apex. Further Google won't do all 10 of them - I see it do only first 2-3 and then start giving 620 message. There is no delay in Apex.
2. If you do it from a Visual Force page with an action poller, you have to manually start it.
So if my org has contacts being added on a constant basis with batch load, I will miss out batches that are > 10.
Someone would have to manually run the VF page...