+ Start a Discussion
Richard L JonesRichard L Jones 

Apex Not Triggering

Hi all,

Well, I'm in well over my head here :) We have a custom object on our opportunity pages called Financial Projections. This takes data from the opportunity page and performs calculations to show annual revenue and annual gross margin, and then displays them in a related list object.

The problem I've got, apart from the developer having disappeared, is that the financial projection aren't being generated properly.

Basically, if a user completes all the required fields on the opportunity and saves it, the projections will generate correctly.

However, if they don't enter all the fields but move the opp forward a stage, and at that point enter all the required fields, the financial projections doesn't trigger at all.

Finally, and confusingly, if they populate the correct fields at the start, move forward a stage, and then alter the figures, the financial projections will correctly update. 

So, it's almost as if it's a one-chance deal to the trigger the class. Can anyone help? I'll post the trigger below - the class is 650 lines long so I'm not sure an inline paste will work here.

Thanks in advance
Richard

trigger CRMS_OpportunityTrigger on Opportunity (before insert, after insert, after update, before update) 
{
    public static boolean blnUpdate = false;
    //public static integer intCount = 0;
    if(trigger.isInsert && trigger.isBefore)
    {
        CRMS_OpportunityTriggerHandler objClass = new CRMS_OpportunityTriggerHandler();
        objClass.beforeInsert(trigger.new);
    }
    if(trigger.isInsert && trigger.isAfter)
    {
        CRMS_OpportunityTriggerHandler objClass = new CRMS_OpportunityTriggerHandler();
        objClass.afterInsert(trigger.newMap);
    }
    if(trigger.isAfter && trigger.isUpdate)
    {
        //if(intCount <2)
        if(!blnUpdate)
        {
          CRMS_OpportunityTriggerHandler objClass = new CRMS_OpportunityTriggerHandler();
          objClass.afterUpdate(trigger.newMap, trigger.OldMap);
          //intCount = intCount + 1;
          blnUpdate = true;
        }
    }
    if(trigger.isUpdate && trigger.isBefore)
    {
        CRMS_OpportunityTriggerHandler objClass = new CRMS_OpportunityTriggerHandler();
        objClass.beforeUpdate(trigger.newMap, trigger.OldMap);
    }
}
Best Answer chosen by Richard L Jones
rajat Maheshwari 6rajat Maheshwari 6

Hi Richard,

Could you please send me the class snippet to my email Id or here, because troubleshoot the issue, will be more fast.


Thanks
Rajat maheshwari
rajatzmaheshwari@gmail.com