This document describes the steps to automate P2 Container Request via Flow.
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:-
public class P2ContainerRequestWrapper { public String sParentRecordId {get;set;} public String sTemplateName {get;set;} public String smsBody {get;set;} public String emailSubject {get;set;} public String emailBody {get;set;} public String defaultMessage {get;set;} //Add another Object to Allow Multiple Recipient public List<Recipient> recipients {get;set;} public class Recipient{ public String firstName {get;set;} public String lastName {get;set;} public String email {get;set;} public String phone {get;set;} public List<RecipientItem> recipient_items {get; set;} } public String firstName {get;set;} public String lastName {get;set;} public String email {get;set;} public String phone {get;set;} public String modeOfCommunication {get;set;} //Email, SMS or Both public DateTime expirationDate {get;set;} public Boolean tfaRequire {get;set;} public String tfaMethod {get;set;} //If tfaRequire is set to True public String requesterFirstName {get;set;} public String requesterLastName {get;set;} }
Set the values in the Wrapper
Create an object of Wrapper and set all the required values
P2ContainerRequestWrapper oWrapper = new P2ContainerRequestWrapper(); oWrapper.sParentRecordId = <Record Id of the record to which the P2 Request will be linked to> oWrapper.sTemplateName = <In case of using the Template to set Email Body and SMS Message from the Template> 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> insert oWrapper; Recipient orecipient = new Recipient(); recipient.cm_datatransfer__P2_Request__c = <Id of the P2Container RequestWrapper> recipient.FirstName = <First Name of the End User to whom request needs to be sent> recipient.LastName = <Last Name of the End User to whom request needs to be sent> recipient.Email = <Email of the End User to whom Request needs to be sent> recipient.Phone = <Phone of the End User to whom request needs to be sent> insert recipient; 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 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>
Serialize the Wrapper
Serialize the wrapper using JSON.serialize method
String sWrapper = JSON.serialize(oWrapper);
Call the Global Method of Managed Package to initiate the process.
cm_datatransfer.GlobalServices.createP2Container(String sWrapper);