You need to sign in to do that
Don't have an account?
Ankit Singh 6
Write a trigger/class which fires when new lead/contact gets created
Hi
I need to write a trigger/class which fires when a new lead/contact gets created in salesforce, also in the same flow the trigger/class calls an 3rd party api.
Is it possible to call a 3rd party api from trigger/class, if so please let me know how to achieve this.
Thanks
I need to write a trigger/class which fires when a new lead/contact gets created in salesforce, also in the same flow the trigger/class calls an 3rd party api.
Is it possible to call a 3rd party api from trigger/class, if so please let me know how to achieve this.
Thanks
We cannot call any API from apex trigger, you must need to use asynchronous methods like @future(Future Method) or Queueable Interface from that you can execute your API request.
Future Method - https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_invoking_future_methods.htm
Queueble Interface - https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_queueing_jobs.htm
Thanks & Cheers,
Jigar
http://amitsalesforce.blogspot.in/2015/06/trigger-best-practices-sample-trigger.html
Create one Trigger "AccountTrigger"
Create one Trigger Handler Class
Create one Trigger Action Class
NOTE:- If you want to call API from Trigger then you should add Future method.
Please mark this as solution if this will help you.
Thanks
Amit Chaudhary
You have to use @future anotation in trigger to call the external api through trigger. You have to write some thing like below code :
public class TriggerHelper{
@future(callout=true)
public static void callApi(List<sObject> objlst){
//write your code here for call the api
}
}
call this utility method in your trigger like as following :
trigger contactTriggger on contact(after insert){
TriggerHelper.callApi(trigger.new);
}
Please let me know if this solution help you.
Thanks
Jitendra