You need to sign in to do that
Don't have an account?
Nathaniel Neblett 18
Help with Test Class for Invocable Apex Action called from Flow
public without sharing class dedupeLeadProductInterest { public class FlowInputs { @InvocableVariable public String varCombinedProductUnMod; @InvocableVariable public String LeadId; } @InvocableMethod public static void updateLead (List<FlowInputs> requests) { List<Id> LeadIds = new List<Id>(); for (FlowInputs request : requests) { LeadIds.add(request.LeadId); } List<Lead> leads = [SELECT Id FROM Lead WHERE Id IN : LeadIds]; List<Lead> LeadsToUpdate = new List<Lead>(); for (FlowInputs request : requests) { for (Lead MyLead : leads) { if (MyLead.Id == request.LeadId) { String varCombinedProductUnMod = request.varCombinedProductUnMod; String LeadId = request.LeadId; List<String> duplicateRemoveList = new List<String>(new Set<String>(varCombinedProductUnMod.split(';'))); String varApexModifiedCombinedProd = String.join(duplicateRemoveList, ';'); MyLead.Product_Interest__c = varApexModifiedCombinedProd; LeadsToUpdate.add(MyLead); } } } database.update(LeadsToUpdate); } }
Looking for some help to write a test class for the above invocable method used in an apex action from flow. Unsure how to go about writing a test class for flow inputs. Thanks in advanced
Please use the below test class:
Thanks,
Maharajan.C
All Answers
Please use the below test class:
Thanks,
Maharajan.C
Thanks @Maharajan.C
I solved it with the following ( before i saw you post)
i was forgetting to create the record in my test class. All good now. Thanks.
posting my solution too as it might be usefull for others
I need help with the test class for the callable Apex action called from a flow
public with sharing class ECO_DataAccess_CancellationArco {
//input details that comes to apex from flow
public class FlowInputs{
@InvocableVariable
public String naturalpersonid;
@InvocableVariable
public String originTag;
@InvocableVariable
public Boolean dataTreatment;
}
//output returns from apex to flow
public class Response{
@InvocableVariable
public Boolean isCanceled;
}
@InvocableMethod(label = 'Acc_Cancellation_Arco' description = 'Execute endpoint to core to remove an account.')
public static List<Response> getCancellationArco(List<FlowInputs> flowInputs) {
List<Response> responses = new List<Response>();
Response res = new Response();
FlowInputs request = flowInputs[0];
Map<String, String> valuesPath = new Map<String, String>();
Map<String, Object> bodyRequest = new Map<String, Object>();
List<Map<String, Object>> cancellationArcoCheck = new List<Map<String, Object>>();
valuesPath.put(':natural_person_id', request.naturalpersonid);
if(String.isNotEmpty(request.originTag)){
bodyRequest.put('originTag', request.originTag);
}
bodyRequest.put('dataTreatment', request.dataTreatment);
System.debug(bodyRequest);
ECO_DataAccess_Integrations integration = ECO_DataAccess_Integrations.getInstance();
integration.result = integration.sendRequest('ECO_CancellationArco', JSON.Serialize(bodyRequest), valuesPath);
if(integration.result.status) {
if(integration.result.response.getStatusCode() == 200) {
System.debug(integration.result.response.getBody());
Map <String, Object> response = (Map <String, Object>) JSON.deserializeUntyped(integration.result.response.getBody());
Object data = (Object) response.get('data');
Map<String, Object> results = (Map<String, Object>)data;
res.isCanceled = (Boolean) results.get('cancellationArco');
} else {
res.isCanceled = false;
system.debug(integration.result.response.getBody());
}
} else {
res.isCanceled = false;
system.debug(integration.result.errorMessage);
throw new AuraHandledException('User has an active product');
}
responses.add( res );
return responses;
}
}