3

I'd like to use the Salesforce account Geolocation fields (billing address latitude and longitude) to assign accounts to specific geographical zones.

Salesforce automatically updates the billing address latitude and longitude when the account is created - the problem I'm running into is the slight (second or less) lag time between the creation of the record, and Salesforce's automatic update of the coordinates.

When the coordinates are referenced in a class called by the After Insert trigger, they return null.

The only workarounds I've come up with are - using the Google Maps API (but callout limits may be exceeded), trying a hacky sleep function, or writing a schedulable batch that processes new accounts - but I could see this frustrating users as they wait for the info to be populated on their new accounts.

Hoping there's another option I'm missing here - thanks for any advice.


Just a warning to anyone else who may need to do something similar - got this working thanks to the advice here but initially the update of the Geolocation fields still bypassed the After Update trigger - even with the Bypass Trigger checkbox unchecked. A Process Builder process (that ran on account creation/update) seemed to be the cause. Once that process was deactivated all began to work as expected.

1
  • 2
    You may need to run a scheduled job on a daily basis to do this as I don't believe Salesforce populate those fields immediately if you've enabled them.
    – crmprogdev
    Jul 29, 2018 at 12:55

2 Answers 2

4

The geocoding data rules are asynchronous and you will not have access to their data in the after insert operation because the geocoding rule is executed after the insert transaction is completely finished.

Because the geolocation data is set in an update, you can use an update trigger instead and use the geolocation data on the records in the trigger.

Also, be mindful that there's an accuracy field set during geocoding which you may need to inspect to ensure you're assigning records based on your specific business needs.

https://help.salesforce.com/articleView?id=data_dot_com_clean_geocode_information_fields.htm

2

You can access those values in trigger. In your data-management settings uncheck bypass triggers. enter image description here

So when you create an Account

  1. Insert trigger will fire
  2. In New transaction, SF will update geolocation on the newly inserted account
  3. Your Update trigger will fire, You can capture it by writing before update/after update trigger.

Source: https://salesforce.stackexchange.com/a/216216/19118

2
  • Sorry no-thanks-in-the-comments rule, but this saved me hours. Thank you.
    – resedasue
    Jul 29, 2018 at 21:24
  • You might want to make this answer as approved .. Would help other people looking for solution. Jul 29, 2018 at 21:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .