Retrieve the latest consent using APEX API

Users can use this APEX API to retrieve the latest consent by passing Individual Id. Cloud Compliance’s Grouping Rules of Individual will associate each and every contact or lead record with an Individual. 

All the consent management is implemented around Individual Object. Hence just by passing the Individual Id or list of Individual Ids to the Consent Retrieval API user can fetch the latest consents associated with that Individual.

The method used for this APEX API is as follows –

List < String > individualList = new List < String > {
‘0PK5w000000TNTGGA4’
}; //Pass the Individual Id or List of Idsmap reqMap = new map{    PCCC_DM.PCL_Constants.INDIVIDUALID_LIST => individualList};map> response =
newmap < String, List < ContactPointTypeConsent >> ();
response = PCCC_DM.PCL_ConsentService.getConsentData(reqMap);
for (ContactPointTypeConsent consentRec: response.get(‘0PK5w000000TNTGGA4’)) {
system.debug(‘ >>>>>’ + consentRec);
}


Solution Steps
 

1. Navigate to a Salesforce Contact/Lead record for which users want to fetch the latest consent record via APEX API. Here contact record is used as a sample. This contact record contains 2 consents (Contact Point Type Consent Records) – Sales -Email as Opt-In and Sales – SMS as Opt-Out.

2. This contact record is associated with the Individual.  

3. Go to the Individual record and get the Id from URL. The id is highlighted for reference in the screenshot –

4. Open the Salesforce Developer Console. Prepare the create getconsentdata method by passing the IndividualId as parameters and execute the code.

Note: Here ‘For’ loop is used to see details of the fetched consent records. This is optional.
 

The APEX API with For loop is as follows –

List < String > individualList = new List < String > {
‘0PK5w000000TNTGGA4’
};
map < String, Object > reqMap = new map < String, Object > {
PCCC_DM.PCL_Constants.INDIVIDUALID_LIST => individualList
};
map < String, List < ContactPointTypeConsent >> response = new
map < String, List < ContactPointTypeConsent >> ();
response = PCCC_DM.PCL_ConsentService.getConsentData(reqMap);
for (ContactPointTypeConsent consentRec: response.get(‘0PK5w000000TNTGGA4’)) {
system.debug(‘>>> Id >>’ + consentRec.Id);
system.debug(‘>>> Name >>’ + consentRec.Name);
system.debug(‘>>> CreatedDate >>’ + consentRec.CreatedDate);
system.debug(‘>>> LastModifiedDate >>’ + consentRec.LastModifiedDate);
system.debug(‘>>> PartyId >>’ + consentRec.PartyId);
system.debug(‘>>> DataUsePurposeId >>’ + consentRec.DataUsePurposeId);
system.debug(‘>>> PrivacyConsentStatus >>’ + consentRec.PrivacyConsentStatus);
system.debug(‘>>> EffectiveFrom >>’ + consentRec.EffectiveFrom);
system.debug(‘>>> EffectiveTo >>’ + consentRec.EffectiveTo);
system.debug(‘>>> PCCC_DM__CC_Contact_Point_Type__c>>’ +
consentRec.PCCC_DM__CC_Contact_Point_Type__c);
system.debug(‘>>> PCCC_DM__CC_Capture_Contact_Point_Type__c >>’ +
consentRec.PCCC_DM__CC_Capture_Contact_Point_Type__c);
}



5. This API returns Consent records related to a Contact record. Here the two consent fetched is highlighted in screenshots. One is Opt-Out and another is Opt-In. These details can be further used as per the integration with other systems.