Guest User

Untitled

a guest
Jul 16th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1.  
  2. trigger RequestTrigger on Request__c (after insert) {
  3.  
  4. ID ATOP_ID = [select id from recordtype where Name = 'ATOP' and SobjectType = 'Request__c'].id;
  5. ID AIA_ID = [select id from recordtype where Name = 'AIA' and SobjectType = 'Request__c'].id;
  6.  
  7. //set<ID> ATOP_OppIDs = new set<ID>();
  8. //set<ID> AIA_OppIDs = new set<ID>();
  9. set<ID> ATOP_IDs = new set<ID>();
  10. set<ID> AIA_IDs = new set<ID>();
  11.  
  12. If (trigger.isAfter && trigger.isInsert) {
  13.  
  14. for (Request__c r : trigger.new) {
  15. //If (r.RecordTypeId == ATOP_ID) ATOP_OppIDs.add(r.Opportunity__c);
  16. //If (r.RecordTypeId == AIA_ID) AIA_OppIDs.add(r.Opportunity__c);
  17. If (r.RecordTypeId == ATOP_ID) ATOP_IDs.add(r.Account__c);
  18. If (r.RecordTypeId == AIA_ID) AIA_IDs.add(r.Account__c);
  19. }
  20.  
  21.  
  22. //Opportunity[] opp1 = [select accountid from opportunity where id in :ATOP_OppIDs];
  23. //for (Opportunity o : opp1) {ATOP_IDs.add(o.accountid);}
  24.  
  25. //Opportunity[] opp2 = [select accountid from opportunity where id in :AIA_OppIDs];
  26. //for (Opportunity o : opp2) {AIA_IDs.add(o.accountid);}
  27.  
  28. system.debug('ATOP_IDs: ' + ATOP_IDs);
  29. system.debug('AIA_IDs: ' + AIA_IDs);
  30.  
  31. Account[] acctsATOP = [select id, name, Last_ATOP_Request__c from account where id in :ATOP_IDs];
  32.  
  33. for (Account a : acctsATOP) {a.Last_ATOP_Request__c = system.Date.today();}
  34. update acctsATOP;
  35.  
  36. Account[] acctsAIA = [select id, name, Last_AIA_Request__c from account where id in :AIA_IDs];
  37.  
  38. for (Account a : acctsAIA) {a.Last_AIA_Request__c = system.Date.today();}
  39. update acctsAIA;
  40.  
  41. }
  42. }
Add Comment
Please, Sign In to add comment