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
tschatztschatz 

Callout from triggers are currently not supported.

I have a trigger on the Opportunity Object that calls a class. That class then calls another class that makes an HTTP GET request to a Web Service.
 
However I get the error:
 
Callout from triggers are currently not supported.
 
How can I send data to an external Web Service using Apex code? I have read (or am reading) chapter 12 of the reference manual, but obviously missing something.
 
Help please.
 
_t
 
Ron HessRon Hess
This feature is intended to be called from a class, that class is invoked by a web service method (global WebService method)

you can launch that (webservice) from a button, scontrol, inline scontrol, scontrol in a dashboard, etc, using ajax execute methods, found in the ajax toolkit, examples are found in the AJAX Tools application on the AppExchange
tschatztschatz
Thank you for the information.
 
Please excuse my ignorance, as you can tell I'm a newb. If I were to create an S-Control would I then be able to call that S-Control automatically from a Trigger or class called by a Trigger?
 
What I need to happen is for that Web Service to be called when an Opportunity Stage is set to Closed Won. That can happen either by a user setting it manually or triggered by a Workflow. Any advice, direction, or workarounds would be appreciated.
 
Thanks in advance.
 
_t
SuperfellSuperfell
You should look at the Outbound Messaging feature, its queued and asynchronous, can batch up messages, etc. Basically its designed to handles these kinds of use cases.
tschatztschatz

Are you refering to the Outbound Messaging Feature that is part of a Workflow and is created using the Salesforce UI? If so, that is where I started in the process and ran into a wall when I needed to access information across multiple Objects and include values from custom fields.

Although you are exactly right, that is what I am looking to do. Is there anyway to access Outbound Messaging from Apex Code, that would allow me to send whatever values I wanted? If so, could you please point me in the right direction. I have been using the reference guide but have missed that or not looking in the right place.

Please and thank you.

_t

SuperfellSuperfell
Yes, the Workflow Outbound Messaging feature.

No, OM will only send fields from the firing object, but you can configure it to send you a sessionId as well, so its easy to call back to saleforce to get whatever additional data you might need.

Message Edited by SimonF on 11-16-2007 08:36 AM

tschatztschatz
Thanks for the info Simon!
 
That's a bummer that you can call an Outbound Message from a triggered event using the UI but not from a triggered event using Apex code. Is there a technical reason why this is not allowed or has it just not been built into the language yet?
 
_t
valentinoromelivalentinoromeli
Big trouble if it cant be done
JimPDXJimPDX
Ron - is this old thread still true? Doesn't Winter 09 now let you call external web services through triggers?

1- We have added the servers into Remote Site Settings to presumably open up outbound security
2- We created a class called from a trigger to invoke the web service
3- The APEX log is returning "System.CalloutException: Callout from triggers are currently not supported."

I thought this new feature alleviated this problem?

http://ideas.salesforce.com/article/show/10077643/Allow_Apex_Triggers_to_call_External_Web_Services
SuperfellSuperfell
You have to use the @future feature.
valentino rijhevalentino rijhe

Call outs give you maximum flexibility but I'm wondering if you would like to use it.
Maybe there is an easier solution.
Workflow with Outbound Messaging is easier to implement there is a lot that you don't have to build yourself.

The resting part (extra business logic) you can build on your notification listener server (ASP.NET/PHP web service/etc).

Hopefully this helps you out.

regards,
Valentino Rijhen

IvarIvar

Can anyone tell me if there are any planned changes to this?

 

I realize that calling an external service during a trigger event will severly slow down user experience in many cases, but the alternative of using a Workflow with Outbound Messaging is just not a good one.

 

 

  • Firstly workflows are a finite resource and we really don't want to spend precious workflow slots if we don't absolutely have to. 
  • Secondly I really dislike the thought of having an external service handling salesforce-centric business logic, that could and should be handled internally.  I guess that could be avoided by having an outbound message call an external service, which in turn would call in again to an apex webservice that would handle the data processing, but this just seems like the long way around a simple problem.

 

  

sdavidow9sdavidow9

I thought I would throw my 2 cents in here...I just read through this thread because I was getting the:

 

System.CalloutException: Callout from triggers are currently not supported.

 

And this thread popped up in that search.  

 

I simply added the:

@future (callout=true)

 

peice to the beginning of my code (using future callouts elsewhere as well) and it worked like a charm.  Yes, it was already a void call and everything was set for future, so I didn't have any of those problems...oh, and the call is to update an external system, so I'm not concerned about delay in the call, but this solved my problem.

 

Just thought I'd try to help.