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
ranirani 

Is apex trigger on opportunity based on stage name of opportunity

Hi All,
 
I have created a trigger on opportunity which sould fire both before insert and before update. Its working fine for all stages of opportunity when the opportunity is edited i.e. before update, but the trigger is not firing when the opportunity is created for few stages and firing for few stages. The trigger is getting fired when an opportunity is created with stage name as first call schedule or proposal and not firing for other stages i.e. lead generated, executive overview or analysis or feebback/demo or closed won or closed lost or stalled.
 
Help is appreciated.
 
Regards,
Rani


Message Edited by rani on 07-11-2008 07:41 AM
SiriusBlackOpSiriusBlackOp

It should fire for all of them.  It is more likely that your code is not doing what it should or that you have used a Try block to catch exceptions but not you are not handling them properly.  Either way your code seems to be exiting gracefully without doing what it should. 

 

To test that the code is firing you could try adding a temporary fake error to the trigger at the beginning of your code to see if it is in fact firing or not.  

Try Using:      trigger.new[0].addError("It Worked!");

werewolfwerewolf
And you can turn on debug logging for yourself and then watch it run in the debug logs.
ranirani

As said i've included a error method i.e newOpp[0].addError('Something'); and found that the trigger was getting executed (only when created) when the stage name is first call scheduled or proposal and didnt for all other stages.

werewolfwerewolf
Even so you should turn on the debug log so you can examine its execution.
jrotensteinjrotenstein
Might you have other Triggers that are changing values, or perhaps some Validation Rules that are interfering with the saved values?