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
GregWaxGregWax 

Call Web Service from Apex Trigger to perform Address Standardization and geo-coding real time

Page: Account

 

Trigger:  before insert, before update

 

Debug Log:

 

METHOD_ENTRY|[315]|01pP00000008Yot|Mappable.invokeWebService(System.Http, System.HttpRequest)

 

METHOD_ENTRY|[170]|System.Http.send(APEX_OBJECT)

 

EXCEPTION_THROWN|[170]|System.CalloutException: Callout from triggers are currently not supported.

 

 

It has been suggested to use @future, however I need real time validation and @future methods are asynchronous.

 

I appreciate any suggestions

EIE50EIE50

Hi Greg,

 

Currently call outs are not supported in apex triggers. You may need to invoke an apex class from the trigger and do the call outs in your apex class. Do have a look at this document, Apex CallOuts .

 

Thanks.

forecast_is_cloudyforecast_is_cloudy

Greg,

As indicated earlier, there is currently no way to make syncronous callouts from a Trigger context. Using  the @future notation to make the callout aysnc is really the only option (short of developing a custom VF page for your CRUD use case). Though it would obviously be ideal to perform the address standardization and geo-coding in real-time, what's the exact issue with making them 'real near-time' (i.e within minutes/secs of the update/insert) with a @future callout? Is that that the user won't know if the address they entered was incorrect?

GregWaxGregWax

Thank you for confirming the issue about synchronous web calls in trigger

GregWaxGregWax

The business requirements specifies that the address be validated while the user is still on the Account page.

 

If the address is incomplete/wrong then the user has a chance to correct before saving.

 

The same apec class that I created works for Bulk update and for a mapping button.

 

Using the web call asynchronously defeats the goal.  Once a the user leaves the Account screen they don't take the time to review the record.

 

Thanks very much for you help.

GregWaxGregWax

Instead of using a trigger, Is there a field rule or workflow that could call my apex web service?

forecast_is_cloudyforecast_is_cloudy

Not really. You could setup an Outbound Message via a workflow that calls out to an external web service (but not to an Apex web service) every time an Account record is updated. However that is also async and so won't meet your requirement either. Sorry to be bearer of bad news :(

Venkata Krishna S 1Venkata Krishna S 1
Hi Greg,
I have same requirement for Address Standardization on Account object.
Can you please post the sample webservice code and help me how to call that webservice from my application.