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
pfarrellpfarrell 

SOA from Apex Trigger?

I am new to Apex Code development and am trying to get a trigger to call a web service (imported into Apex Code via wsdl).

This is a simple web service hitting http://www.webservicex.net/WCF/ServiceDetails.aspx?SID=51 (a whois lookup service) for a test.

The wsdl imported correctly and I am now trying to utilze the web service in an Apex trigger.  Here's the code for the call.

trigger helloWorldTrigger on Account (before insert) {
Account[] accs = Trigger.new;
MyHelloWorld.addHelloWorld(accs);
}
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger helloWorldTrigger caused an unexpected exception, contact  your administrator: helloWorldTrigger: execution of BeforeInsert caused by: System.CalloutException: Callout from triggers are currently not supported.: Class.wxWhois.whoisSoap.GetWhoIS: line 19, column 13

I'm reading this error as an indication that Apex triggers currently cannot perform an interaction with web services.  Am I interpreting this error correctly?
mtbclimbermtbclimber
Yes, you are interpreting this error correctly. You can not connect to an external service in the context of a trigger.  Callouts can be invoked through explicit operations only currently.  You can add your callout to a webservice method in Apex and then invoke that through the API which includes the AJAX Toolkit for UI interactions.
pfarrellpfarrell
thanks for the quick reply mtbclimber.
pfarrellpfarrell
I have a followup clarification request.

Is there any way to use SalesforceSOA through Apex without being in response to UI action (i.e. a button click)?
Ron HessRon Hess
you can call your Apex Code via an external webservice, at which point your SOA class can be invoked.
pfarrellpfarrell
Thanks Ron

Message Edited by pfarrell on 08-22-2007 07:01 AM

OldDeadBugOldDeadBug

This is a rather old thread so this process may have been updated since 2007, but we were able to call a web service from a trigger by ensuring the called service method was set with:

 

 

global with sharing class IOW_Update
{
  @isfuture (callout=true)

  public static void SuspendIOWOrder(id OppId) //this method is called by the trigger

     {
      suspendOrder(OppId)      // this method calls the actual webservice method
     }
}

 This appears to be working as no exception is being thrown in the logs.