Callout from Record Triggered Flow in Salesforce

|
| By Webner

Step 1: We need to create a flow of Record triggered types.

  • Select an Object and configure the trigger according to the requirement.
    Flow in Salesforce
  • Set Entry Condition: Add the condition for which this record triggered flow fired. For example here, if the JSON_Data__c value is changed to TRUE, triggers the record-triggered flow.
  • When to Run the Flow for Updated Records
    Salesforce
    Choose the required option.
  • Optimize the flow for Action and related Records and click on Done.
    Flow

Step 2:

  • Choose the Apex Action.
  • Select the apex class in Action and choose the variable that we want to pass to the apex class.
    apex
    variable

APEX class(Sample Code)

InvocableMethod Annotation
The class having the @InvocableMethod annotation is exposed to users of invocable actions in the Flow Builder.

public class ActivityHelperClass {
@InvocableMethod(label='Get Activity Fileds' description='Returns activity fields' category='Acord_Form_Tracking__c')
public static void getActivity(List<String> ids){
List<Acord_Form_Tracking__c> transactionIDList;
String acfrmId=ids.get(0);
transactionIDList=[SELECT Id, Transaction_ID__c FROM Acord_Form_Tracking__c WHERE Id =: acfrmId ];
String transactionID=transactionIDList[0].Transaction_ID__c;
system.debug('***************GETFORM Welcome ActivityHelperClass ---------'+transactionIDList[0].Transaction_ID__c);
String payload ='tracking_id='+transactionID;
system.debug('payload in ACtivity'+payload) ;
callout(transactionID);
}
@future(callout = true)
public static void callout(String transactionID)
{
String accestokenvalue=FetchAcordFormFromFormcruise.login();
system.debug('accesstoken in ACtivity'+accestokenvalue) ;
try {
HttpRequest activityformreq = new HttpRequest();
activityformreq.setEndpoint('https://formcruise.webnerserver.com/api/get-form-activities?tracking_id='+transactionID);
activityformreq.setHeader('access-token',accestokenvalue);
activityformreq.setMethod('GET');
system.debug('------activityformreq start ---');
system.debug(activityformreq);
system.debug('------activityformreq End ---');
Http h2 = new Http();
HttpResponse activityFormResponse = h2.send(activityformreq);
system.debug('activityFormResponse'+activityFormResponse.getBody());
if(activityFormResponse.getStatusCode() == 200) {
Map<String, Object> activityFormResponseMap = (Map<String, Object>) JSON.deserializeUntyped(activityFormResponse.getBody());
system.debug('activityFormResponseMap'+activityFormResponseMap);
Map<String, Object> activityFormDataMap=(Map<String, Object>) activityFormResponseMap.get('data');
system.debug('DATA__________'+activityFormDataMap);
List<Object> objectList= new List<Object> ();
List<Acord_Form_Tracking__c> activityFieldList =new List<Acord_Form_Tracking__c>();
for(String Key:activityFormDataMap.KeySet())
{
objectList = (List<Object>) activityFormDataMap.get(Key);
system.debug('---------KEY------'+Key);
}
Map<String,Object> formvalueMap=(Map<String, Object>) objectList[0];
System.debug('formvalueMap'+formvalueMap);
String activityType=(String) formvalueMap.get('activity_type');
System.debug('activityType----------'+activityType);
String activity_by=(String) formvalueMap.get('activity_by');
System.debug('activity_by-----------'+activity_by);
List<Acord_Form_Tracking__c> acrdList= [SELECT Id, Transaction_ID__c, Last_Activity__c, Activity_By_Email_Id__c, Recipient_Email_Id__c FROM Acord_Form_Tracking__c];
for(Acord_Form_Tracking__c aft:acrdList )
{
if(aft.Transaction_ID__c==transactionID)
{
system.debug('inside if condition***************');
if(activityType.contains('Emailed'))
{ system.debug('inside if condition emailed***************');
aft.Last_Activity__c='Form Email';
aft.Recipient_Email_Id__c=activityType.substring(16);
aft.Activity_By_Email_Id__c=activity_by;
activityFieldList.add(aft);
}
else{
aft.Last_Activity__c=activityType;
aft.Activity_By_Email_Id__c=activity_by;
aft.Recipient_Email_Id__c='';
activityFieldList.add(aft);
}
}update activityFieldList;
}
}
} catch (System.CalloutException e){
System.debug('Error-' + e.getMessage());
}
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *