While developing applications in force.com, sometimes we need to consume external web service in apex trigger. But, callouts cannot be made from apex triggers as that restricts database transaction until the callout is completed and the time limit for this is up to 120 seconds.You can find other callout limits here.
The only way to execute a callout from a trigger is to run it asynchronously and this can be achieved by executing a method with the @future method. Future methods execute asynchronously i.e. one does not need to wait for a response. The thing to keep in mind is, a future method can have native calls, as well as, they can make a call out to an external web service and hence, in order to enable the future method to allow callouts, an extra parameter “Callout=true” needs to be passed.
For example: –
You have a requirement to call a web service after updating the contact record. Web service callout method (in this example callWebService(Contact cnt) ) is in the Util class which is getting consumed in apex after update trigger.
Apex trigger’s code:
Greytrix as a Salesforce Product development partner offers a wide variety of integration products and services to the end users as well as to the Partners across the globe. We offers Consultation, Configuration, Training and support services in out-of-the-box functionality as well as customizations to incorporate custom business rules and functionalities that requires apex code incorporation into the Salesforce platform.
Greytrix has some unique solutions for Cloud CRM such as Salesforce integration with Sage Enterprise Management (Sage X3), Sage Intacct, Sage 100 and Sage 300 (Sage Accpac). We also offer best-in-class Cloud CRM Salesforce customization and development services along with services such as Salesforce Data Migration, Integrated App development, Custom App development and Technical Support to business partners and end users.
Greytrix GUMU™ integration for Sage ERP – Salesforce is a 5-star app listed on Salesforce AppExchange.
For more information, please contact us at firstname.lastname@example.org. We will be glad to assist you.