SHARE
TWEET

Untitled

tototototo123 Sep 20th, 2019 94 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static void ApplyUpdateRules(List<Transaction__c> newTransactions) {
  2.         system.debug('### START TR001_Transaction : ApplyUpdateRules');
  3.         List<Transaction__c> transactionsToUpdate = new List<Transaction__c>();
  4.         Integer createdsinceXdays = GlobalPropertiesUtils.getIntegerValue('transaction.case.createdsinceXdays');
  5.         system.debug('## : createdsinceXdays ' + createdsinceXdays);
  6.         Datetime today = System.now();
  7.         Datetime todayMinusX = today.addDays(-createdsinceXdays);
  8.         system.debug('## : todayMinusX ' + todayMinusX);
  9.         List<Case> cases = new List<Case>();
  10.         cases = [SELECT Id, AccountId, CreatedDate FROM Case WHERE CreatedDate <=: todayMinusX ORDER BY CreatedDate DESC];
  11.         system.debug('## : cases ' + cases);
  12.         if(!newTransactions.isEmpty() && !cases.isEmpty()) {
  13.             for (Transaction__c newTransaction : newTransactions) {
  14.                 if(newTransaction.TYPECO__c == 'Order') {
  15.                     for (Case newCase : cases) {
  16.                         if(newTransaction.ACCOUNT__c == newCase.AccountId) {
  17.                             newTransaction.CASEORIGIN__c = newCase.Id;
  18.                             transactionsToUpdate.add(newTransaction);
  19.                             break;
  20.                         }
  21.                     }
  22.                 }
  23.             }
  24.         }
  25.         system.debug('## : transactionsToUpdate ' + transactionsToUpdate);
  26.         if(!transactionsToUpdate.isEmpty()) {
  27.             update transactionsToUpdate;
  28.         }
  29.        
  30.         system.debug('### END TR001_Transaction : ApplyUpdateRules');
  31.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top