New Batch#100 (10th Nov 2021) - Salesforce Admin + Dev Training (WhatsApp: +91 - 8087988044) :https://t.co/p4F3oeQagK

Friday 10 August 2012

Callout Integration and Apex

Question:
I have to call to an external webservice everytime a new account is created. My question is, what is the best way to do so?

I thougt about creating an after create trigger that will invoke the method in the class that was generated from the WSDL import. Would that make sense?

If so, how can I import a class into a trigger to use its methods?
Is it the same with Http request or can i make the http request directly from the trigger?

Solution:
Currently in salesforce we can not make callout from trigger directly , You need to write a future class that will invoke the callout using wsdl generated classes. So in fact this call will be asynchronous call rather than realtime callout.

For example-  you have a wsdl genarated class named "WSDlGeneratedClass" , And you will have to write a future method like -
public class future class
{
 @future(callout=true)
 public static void calloutMethod()
 {
  // write code to invoke "WSDlGeneratedClass" class methods to make callout
 }
}

Now this method you will need to call from trigger.

Yes its also with HTTP callout  (cannot make any kind of callout from trigger directly).

No comments:

Post a Comment

Labels