Create consent based on APEX API

Updated on March 20, 2023

Users can use this APEX API-based consent creation method for contacts and leads to address Contact Bulk Import and other scenarios where an implicit contact/lead creation is required. In the use cases, the Consent Creation is by an APEX API interface.

The method used for this APEX API is as follows –

map < String, Object > inputDataItem = new map < String, Object > {
PCCC_DM.PCL_Constants.CONSENT_GIVER_ID => '0PK2x0000004C98GAE',
PCCC_DM.PCL_Constants.SHORT_CODE => 'MAR-PHO',
PCCC_DM.PCL_Constants.CAP_CON_POINT_TYPE => 'Web',
PCCC_DM.PCL_Constants.STATUS => 'OptIn'
};
map < String, Object > inputData = new map < String, Object > {
PCCC_DM.PCL_Constants.CONSENT_REQUEST => new List < Object > {
inputDataItem
}
};
system.debug(PCCC_DM.PCL_ConsentService.createConsent(inputData));

Mandatory Parameters

PCCC_DM.PCL_Constants.CONSENT_GIVER_ID – mandatory
PCCC_DM.PCL_Constants.SHORT_CODE – mandatory
PCCC_DM.PCL_Constants.CAP_CON_POINT_TYPE – optional
PCCC_DM.PCL_Constants.STATUS – mandatory

Where CONSENT_GIVER_ID is the Individual ID of the Contact/Lead object record.

SHORT_CODE is a field that will store a shortcode that is used to link the Data Use Purpose record for consent processing. This field will need to be unique across all records for “Data Use Purpose” ( concatenate the first three initials of Purpose & Channel name eg. if “Purpose = Marketing” & “Channel = Phone” then shortcode = “MAR-PHO”)  

CAP_CON_POINT_TYPE refers to one of the mandatory fields on Contact Point Type Consent which is basically the contact point used to capture consents. (Restricted Picklist Field)

STATUS  refers to one of the mandatory fields on Contact Point Type Consent which is Privacy Consent Status (Picklist Field) with the value as OptIn or OptOut.

This status basically confirms whether the individual associated with this record agrees to this form of contact.

Solution Steps
 

1. Navigate to a Salesforce Contact/Lead record for which users want to manage consent. Make sure that it is associated with the Individual and click on it. For the demo, a contact record is used 

Note– If the individual is not associated with the Contact/Lead record, the user can run the auto Individual batch provided by “Cloud Compliance”. It will automatically create individual records for each Contact/Lead record based on defined criteria. 

For more details about this batch refer to this link Grouping Rules for Individual.

2. Copy the Individual record Id from the URL. The id is highlighted for reference in the screenshot –

3. Open the Salesforce Developer Console. Prepare the create createConsent method by passing the necessary parameters and executing the code.

4. This API returns a consent response containing consentSFId and Status (True/False).

Note – consentSFID is a newly created “Contact Point Type Consent” record id and status =true indicates the successful creation of consent.

5. Navigate to the Consent tab of the contact record in salesforce to validate consent creation. 

6. The Opt-Out Consent created for Marketing Phone is as follows –