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 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;} 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;} public List<Recipient> recipients {get;set;} public class Recipient{ public String firstName {get;set;} public String lastName {get;set;} public List<RecipientItem> recipient_items {get; set;} } public class RecipientItem{ public String interface_class {get; set;} public String value {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.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
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.
Map<String, Object> mapResponse = cm_datatransfer.GlobalServices.createP2Container(String sWrapper);