Advertisement
Guest User

Untitled

a guest
Apr 26th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.09 KB | None | 0 0
  1.     public static String upsertConsentRecord(Consent_Management__c record) {
  2.         String response = '';
  3.  
  4.         try {
  5.  
  6.             if(record != null && String.isBlank(record.Associated_Account__c) && String.isNotBlank(record.Consent__c) && record.Consent__c.equalsIgnoreCase('YES')){
  7.  
  8.                 Account a = new Account();
  9.                 a.Name = record.First_Name__c + ' ' + record.Last_Name__c;
  10.                 a.First_Name__c = record.First_Name__c;
  11.                 a.Last_Name__c = record.Last_Name__c;
  12.                 a.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('HCP').getRecordTypeId();
  13.                 a.Email__c = record.Email__c;
  14.                 a.Consent_Last_Modified_By__c = UserInfo.getUserId();
  15.                 a.Consent_Last_Modified_Date__c = System.now();
  16.                 a.Consent_Method__c = record.Consent_Channel__c;
  17.                 a.Consent_Options__c = 'Consent to Process Data Received';
  18.  
  19.                 upsert a;
  20.  
  21.                 record.Associated_Account__c = a.Id;
  22.             }
  23.  
  24.             upsert record;
  25.  
  26.         } catch(Exception e) {
  27.             response = e.getMessage() + ' ' + e.getStackTraceString() + '\n\n' + JSON.serializePretty(record);
  28.             System.debug('ERROR: ' + response);
  29.         }
  30.  
  31.         return response;
  32.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement