Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trigger OppRecursion on Opportunity (after update) {
- // Create empty opportunity list
- List<Opportunity> oppsToUpdate = new List<Opportunity>();
- //Create empty set
- Set<Id> oppIds = new Set<Id>();
- // Iterate through selected opp records
- for (Opportunity opp : Trigger.new){
- oppIds.add(opp.id);
- }
- // Fetch selected records
- List<Opportunity> opportunityList = [select Id, Description from Opportunity where Id in:oppIds];
- for (Opportunity opportunityRecord:opportunityList){
- //The description will always be updated to Test every time the record is updated
- //This causes recursion because updating the field triggers the after update trigger
- //How can we stop the recursion?
- opportunityRecord.Description = 'Test';
- oppsToUpdate.add(opportunityRecord);
- }
- if (!oppsToUpdate.isEmpty()){
- update oppsToUpdate;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement