Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trigger RequestTrigger on Request__c (after insert) {
- ID ATOP_ID = [select id from recordtype where Name = 'ATOP' and SobjectType = 'Request__c'].id;
- ID AIA_ID = [select id from recordtype where Name = 'AIA' and SobjectType = 'Request__c'].id;
- //set<ID> ATOP_OppIDs = new set<ID>();
- //set<ID> AIA_OppIDs = new set<ID>();
- set<ID> ATOP_IDs = new set<ID>();
- set<ID> AIA_IDs = new set<ID>();
- If (trigger.isAfter && trigger.isInsert) {
- for (Request__c r : trigger.new) {
- //If (r.RecordTypeId == ATOP_ID) ATOP_OppIDs.add(r.Opportunity__c);
- //If (r.RecordTypeId == AIA_ID) AIA_OppIDs.add(r.Opportunity__c);
- If (r.RecordTypeId == ATOP_ID) ATOP_IDs.add(r.Account__c);
- If (r.RecordTypeId == AIA_ID) AIA_IDs.add(r.Account__c);
- }
- //Opportunity[] opp1 = [select accountid from opportunity where id in :ATOP_OppIDs];
- //for (Opportunity o : opp1) {ATOP_IDs.add(o.accountid);}
- //Opportunity[] opp2 = [select accountid from opportunity where id in :AIA_OppIDs];
- //for (Opportunity o : opp2) {AIA_IDs.add(o.accountid);}
- system.debug('ATOP_IDs: ' + ATOP_IDs);
- system.debug('AIA_IDs: ' + AIA_IDs);
- Account[] acctsATOP = [select id, name, Last_ATOP_Request__c from account where id in :ATOP_IDs];
- for (Account a : acctsATOP) {a.Last_ATOP_Request__c = system.Date.today();}
- update acctsATOP;
- Account[] acctsAIA = [select id, name, Last_AIA_Request__c from account where id in :AIA_IDs];
- for (Account a : acctsAIA) {a.Last_AIA_Request__c = system.Date.today();}
- update acctsAIA;
- }
- }
Add Comment
Please, Sign In to add comment