You need to sign in to do that
Don't have an account?
Mathew Andresen 5
bulk trigger review
Hi,
I'm just starting to really get a handle on writing code for bulk triggers, did I do this right? I want to update a field on my opportunity every time a task ray project gets archieved
Thanks,
I'm just starting to really get a handle on writing code for bulk triggers, did I do this right? I want to update a field on my opportunity every time a task ray project gets archieved
Thanks,
trigger TaskRayProject on TASKRAY__Project__c (before update) { set<id> projSet = new set<id>(); List<Opportunity> oppList = new List<Opportunity>(); // get the taskray projects that have been have just been archieved and add to set for (TASKRAY__Project__c proj :Trigger.new) { if(proj.TASKRAY__Status__c == true) { TASKRAY__Project__c oldProj = trigger.oldmap.get(proj.Id); if (oldProj.TASKRAY__Status__c != true) { if(proj.Opportunity__c !=NULL) { projSet.add(proj.Opportunity__c); } } } } // query the opportunty for all items in the set oppList = [SELECT Id, Name, Task_Ray_Project_Completed__c FROM Opportunity WHERE ID IN :projSet ]; // change field to true for(Opportunity opp :oppList) { opp.Task_Ray_Project_Completed__c = true; } update(oppList); }
Code looks good but I did some minor changes. Please have a look. If you think this is good please mark this as solution.
All Answers
Code looks good but I did some minor changes. Please have a look. If you think this is good please mark this as solution.