Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static String upsertConsentRecord(Consent_Management__c record) {
- String response = '';
- try {
- if(record != null && String.isBlank(record.Associated_Account__c) && String.isNotBlank(record.Consent__c) && record.Consent__c.equalsIgnoreCase('YES')){
- Account a = new Account();
- a.Name = record.First_Name__c + ' ' + record.Last_Name__c;
- a.First_Name__c = record.First_Name__c;
- a.Last_Name__c = record.Last_Name__c;
- a.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('HCP').getRecordTypeId();
- a.Email__c = record.Email__c;
- a.Consent_Last_Modified_By__c = UserInfo.getUserId();
- a.Consent_Last_Modified_Date__c = System.now();
- a.Consent_Method__c = record.Consent_Channel__c;
- a.Consent_Options__c = 'Consent to Process Data Received';
- upsert a;
- record.Associated_Account__c = a.Id;
- }
- upsert record;
- } catch(Exception e) {
- response = e.getMessage() + ' ' + e.getStackTraceString() + '\n\n' + JSON.serializePretty(record);
- System.debug('ERROR: ' + response);
- }
- return response;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement