function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ColealarsColealars 

Workflow Field Update causes Before Update Trigger to fire on Opportunity Insert.

I've confirmed that when inserting a new opportunity that has a workflow field update my before update trigger fires.  Can anyone think of a way to prevent this trigger from firing?

 

Here is my trigger:

 

 

trigger opportunity_ae_required on Opportunity (before update) { Map<String, Opportunity> oppy_contact = new Map<String, Opportunity>(); for (Integer i = 0; i < Trigger.new.size(); i++) { if (Trigger.isUpdate && Trigger.new[i].ae_required__c == 1) { oppy_contact.put(Trigger.new[i].id,Trigger.new[i]); system.debug('Trigger.new[i]: ' + Trigger.isUpdate); } } map<Id, OpportunityContactRole> oppycontactroles = new map<Id, OpportunityContactRole>(); for (OpportunityContactRole ocr : [select OpportunityId, Role from OpportunityContactRole where (OpportunityContactRole.Role = 'Account Executive' and OpportunityContactRole.OpportunityId in :oppy_contact.keySet())]) { oppycontactroles.put(ocr.OpportunityId,ocr); } for (Opportunity oppy : system.trigger.new) { system.debug('trigger.isUpdate: ' + Trigger.isUpdate); if (Trigger.isUpdate) { if (oppycontactroles.containsKey(oppy.id) || oppy.ae_required__c == 0) { // Do nothing } else { oppy.addError('Cannot make changes to this Opportunity until an Account Executive has been Selected in the Contact Roles section.'); } } } //for }

 

sfdccoder1sfdccoder1

Try this: 

 

1. Add a checkbox field to the Opprotunity object with default value true.

2. Add code to the beginning of your triggerr which checks this field value.

    - If it's true - uncheck it and return.

    - If it's false - execute trigger code.