...
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;} public String sTemplateNamefirstName {get;set;} public String smsBodylastName {get;set;} public String emailSubjectemail {get;set;} public String emailBodyphone {get;set;} public String defaultMessagemodeOfCommunication {get;set;} //AddEmail, anotherSMS Objector toBoth Allow Multiple Recipient public List<Recipient>DateTime recipientsexpirationDate {get;set;} public classBoolean tfaRequire Recipient{ {get;set;} public String firstNametfaMethod {get;set;} //If tfaRequire is set to True @AuraEnabled public String lastNamerequesterFirstName {get;set;} public String emailrequesterLastName {get;set;} public String phonesTemplateName {get;set;} public List<RecipientItem>String recipient_itemssmsBody {get; set;} } public String emailSubject {get;set;} public String firstNameemailBody {get;set;} public String lastNamedefaultMessage {get;set;} public StringList<Recipient> emailrecipients {get;set;} public Stringclass phone {get;set;}Recipient{ public String modeOfCommunicationfirstName {get;set;} //Email, SMS or Both public DateTimeString expirationDatelastName {get;set;} public BooleanList<RecipientItem> tfaRequirerecipient_items {get; set;} } public String tfaMethod {get;set;} //If tfaRequirepublic isclass setRecipientItem{ to True public String requesterFirstNameinterface_class {get; set;} public String requesterLastNamevalue {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> oWrapper.sTemplateNamefirstName =<First <InName case of usingthe theEnd TemplateUser to setwhom Email Body and SMS Message from the Template> oWrapper.smsBody = <SMS Message request needs to be sent for P2 Request> sent> oWrapper.emailSubjectlastName =<Last <EmailName Subjectof forthe P2End Request>User oWrapper.emailBodyto =whom <Emailrequest Bodyneeds forto P2be Request>sent> oWrapper.defaultMessageemail = <Default Message if Any><Email insertof oWrapper;the cm_datatransfer__Recipient__c recipient = new cm_datatransfer__Recipient__c(); recipient.cm_datatransfer__P2_Request__c = <Id of the P2Container RequestWrapper> recipient.cm_datatransfer__First_Name__c = <First NameEnd User to whom Request needs to be sent> oWrapper.phone <Phone of the End User to whom request needs to be sent> recipient.cm_datatransfer__Last_Name__c = <Last Name of the End User to whom request needs to be sent> recipient.cm_datatransfer__Email__c = <Email of the End User to whom Request needs to be sent> recipient.cm_datatransfer__Phone__c = <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 <LastoWrapper.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 End User tocreating whomthe request needs to be sent> Container> oWrapper.emailrequesterLastName <Last Name <Email of the End User tocreating whomthe Requestcontainer> needs to be sent> oWrapper.phonesTemplateName = <In case of <Phoneusing ofthe theTemplate Endno Userneed to whomset requestSMS needsand toEmail beContent> sent>OR oWrapper.modeOfCommunicationsmsBody = <SMS <ModeMessage to sendbe sent thefor 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> 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(String sWrapper); |