...
This document describes the steps to automate P2 Container Request via Flow.
Table of Contents | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Create an Invocable Apex Class
Create a Wrapper
Under the Invocable class, one need to create a wrapper by setting the following attributes as per requirement:-
Code Block public class P2ContainerRequestWrapper { public String sParentRecordId {get;set;} @AuraEnabled public String sParentRecordIdfirstName {get;set;} @AuraEnabled public String sTemplateNamelastName {get;set;} @AuraEnabled public String smsBodyemail {get;set;} @AuraEnabled public String emailSubjectphone {get;set;} @AuraEnabled public String emailBodymodeOfCommunication {get;set;} //Email, SMS or Both @AuraEnabled public StringDateTime defaultMessageexpirationDate {get;set;} @AuraEnabled public datetimeBoolean lastOnlinetfaRequire {get;set;} public String tfaMethod {get;set;} //AddIf tfaRequire anotheris Objectset to Allow Multiple Recipient True @AuraEnabled public List<Recipient>String recipientsrequesterFirstName {get;set;} public String classrequesterLastName Recipient{{get;set;} @AuraEnabled public String firstNamesTemplateName {get;set;} public String smsBody {get;set;} @AuraEnabled public String lastNameemailSubject {get;set;} public String emailBody {get;set;} @AuraEnabled public String emaildefaultMessage {get;set;} @AuraEnabled public StringList<Recipient> phonerecipients {get;set;} public class Recipient{ @AuraEnabled public List<RecipientItem>String recipient_itemsfirstName {get; set;} @AuraEnabled public BooleanString isTFAEnabledlastName {get;set;} @AuraEnabled public StringList<RecipientItem> tfaMethodrecipient_items {get; set;} } public class RecipientItem{ @AuraEnabled public String firstNameinterface_class {get; set;} @AuraEnabled public String lastNamevalue {get; set;} } }
Set the values in the Wrapper
Create an object of Wrapper and set all the required values
Code Block |
---|
P2ContainerRequestWrapper oWrapper = new P2ContainerRequestWrapper(); oWrapper.sParentRecordId = <Record Id of the record to which the P2 Request will be linked to> |
...
Under the Wrapper, one need not to set if there is only 1 API Key in use, Last Online need not to be set.
...
oWrapper.firstName <First Name of the End User to whom request needs to be sent>
oWrapper.lastName <Last Name of the End User to whom request needs to be sent>
oWrapper.email <Email of the End User to whom Request needs to be sent>
oWrapper.phone <Phone of the End User to whom request needs to be sent>
oWrapper.modeOfCommunication <Mode to send the P2 Request- email, sms or both>
oWrapper.expirationDate <Expiration Date of the Container>
oWrapper.tfaRequire <Set if TFA(2-Factor Authentication) is required on the Container>
oWrapper.tfaMethod <Set the Method- Email or Phone if TFA is enabled>
oWrapper.requesterFirstName <First Name of the User creating the Container>
oWrapper.requesterLastName <Last Name of the User creating the container>
oWrapper.sTemplateName = <In case of using the Template no need to set SMS and Email Content>
OR
oWrapper.smsBody = <SMS Message to be sent for P2 Request>
oWrapper.emailSubject = <Email Subject for P2 Request>
oWrapper.emailBody = <Email Body for P2 Request>
oWrapper.defaultMessage = <Default Message if Any>
P2ContainerRequestWrapper.Recipient oRecipient = new P2ContainerRequestWrapper.Recipient();
oRecipient.FirstName = <First Name of the End User to whom request needs to be sent>
oRecipient.LastName = <Last Name of the End User to whom request needs to be sent>
P2ContainerRequestWrapper.RecipientItem oItem = new P2ContainerRequestWrapper.RecipientItem();
oItem.interface_class = <email or sms>
oItem.value = <emailaddress or phone number based on the interface class>
oRecipient.recipient_items = new List<P2ContainerRequestWrapper.RecipientItem>{oItem};
oWrapper.recipients = new List<P2ContainerRequestWrapper.Recipient>{oRecipient}
|
Serialize the Wrapper
Serialize the wrapper using JSON.serialize method
Code Block |
---|
String sWrapper = JSON.serialize(oWrapper); |
Invoke the P2 Container Service
Call the global mathed of the managed packaged to initiate the creation of P2 Request. The method will return a map holding the record Id of the P2 Request in case of success and error message in case of any failure.
Code Block |
---|
Map<String, Object> mapResponse = cm_datatransfer.GlobalServices.createP2Container(sWrapper); |