+ Start a Discussion
Anto HotelbedsAnto Hotelbeds 

Callout Integration and Apex

Hi,

 

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?

 

Thanks a lot. Regards,

 

Antonio

Best Answer chosen by Admin (Salesforce Developers) 
Alok_NagarroAlok_Nagarro

Hi Anto,

 

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.

All Answers

Alok_NagarroAlok_Nagarro

Hi Anto,

 

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.

This was selected as the best answer
Anto HotelbedsAnto Hotelbeds

Is it the same with Http request or can i make the http request directly from the trigger?

 

Thanks,

 

Antonio

Alok_NagarroAlok_Nagarro

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