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
Max PowerMax Power 

Why are callouts from triggers not currently supported?

Forgive me for asking, as I can see that this topic has a couple of threads dedicated to it, but I'm new to Apex (as of last Friday) and none of these threads discuss this issue to my liking.  I have a rather simple problem.  I'd like to do an external SOAP query when someone adds a new contact to Salesforce to see if I can automatically fill in a bunch of the fields in that record.  I already have a web service that will return this information, but seeing as how I am unable to do this from a trigger (I get the 'Callout from triggers are not currently supported' exception), I believe the following is my only option (correct me if I'm wrong):
 
  1. Create a new Outbound Message from Workflow
  2. Generate the WSDL associated with the outbound message
  3. Create a new web service on my server to handle the outbound message from Salesforce
  4. This new web service must query Salesforce if there is any additional information that I need because the Outbound Message is limited to sending the fields on the table for which the event is defined.
  5. Once I have this additional information I can then perform the actual web query that I wanted to perform from Salesforce, only now the response will come to my application.
  6. Once I have the response I can update the record accordingly, either by defining an Apex web service or by generating a SOAP message as defined by the WSDL for my particular instance.
If this is correct, then I actually find this quite surprising.  Why is this limitation in place?  This seems like a simple task that has been needlessly complicated by an artificial limitation.  I can't even define an Apex web service to handle the Outbound Message?  Why should I be forced to deploy a service to make this possible?
 
Any help or advice you can provide would be appreciated.
 
Thanks!
paul-lmipaul-lmi
They aren't supported in TestMethods either.

The reason why is because all Apex code tests are run prior to any release they do, so it'd most likely cause network/load issues (at least for tests).

As for Triggers, I think they are concerned with the same thing, just on a smaller scale.

They implemented the Outbound messaging concept so they can control and queue requests.

I don't personally agree with this approach, but I do understand why it's there (scalability concerns).

As for your situation, how about the following:

1. Create your own Apex code for creating a contact.
2. Expose it as an SFDC Web Service
3. Implement a new web page on your server for creating contacts (calling this web service).
4. As part of your page's code, it determines said information, populates your variables server side, and then sends that info to your Salesforce web service.

There is only 1 drawback I see in this method which is potential security issue depending on how you implement that web page.

As for plus sides, this would simplify your implementation, and also result in less data flying back and forth betwen SF and your server.
nothingnothing
think about it: it could take several seconds for a callout to complete...this has a direct effect on the ui experience and therefore the perceived performance of salesforce.com
Joseph FerraroJoseph Ferraro
This may be something available via asynchronous apex (someone correct me if I'm wrong)

http://ideas.salesforce.com/article/show/10087624/Asynchronous_Apex
Max PowerMax Power
Thanks to all who have replied.  While I don't like the restriction, I guess it's something that I'm going to have to live with.  At least I understand why it's there.