0

My use case is such that when an Opportunity stage is set to cancelled, related Opportunities have the state set to Cancelled as well.

My Opportunity handler class is getting big so I am passing all the details to a new class where the logic can be evaluated and actioned on.

One problem I have is that it doesn't seem to work when I update records in the UI. However, I cannot troubleshoot the issue because the debug log does not show any of my system.debug statements. I've cranked the debug level to fine or finest on each category but no luck.

Is there a way to get a debug as you traverse through classes?

The code compiles but I'm at a lose of what to do.

Example Handler class code:

public override void afterUpdate(Map<Id, SObject> oldMapGeneric, Map<Id, SObject> newMapGeneric){
    Map<Id, Opportunity> oldMap = (Map<Id, Opportunity>) oldMapGeneric;
    Map<Id, Opportunity> newMap = (Map<Id, Opportunity>) newMapGeneric;
    /*AFTER UPDATE METHODS START*/
    if(!isRecursive)
    {
        cancelAutoRenewal(oldMap, newMap);
        isRecursive = true;
    }
    /*AFTER UPDATE METHODS END*/
}

public static void cancelAutoRenewal(Map<Id, Opportunity> oldMap, Map<Id, Opportunity> newMap)
{
    NPD_Opportunity_Cancel_Auto_Renew.filter(oldMap, newMap);
}

All the magic happens here:

public without sharing class NPD_Opportunity_Cancel_Auto_Renew 
{

public static void filter(Map<Id, Opportunity> oldMap, Map<Id, Opportunity> newMap)
{
    Set<Id> oppys = new Set<Id>();

    // Check if the fields changed
    for(Opportunity o : newMap.values())
    {
        if( 
            o.StageName != oldMap.get(o.Id).StageName &&
            o.Stagename == 'Cancelled' 
        )
            {
                oppys.add(o.Id);
            }
    }

    System.debug('opps filtered are:: ' + oppys);
    getOpps(oppys);
}

public static void getOpps(Set<Id> oppys)
{
    // Find related Opps where the Revnewed From is in the oppys list
    List<Opportunity> oppsToCancel = [SELECT    Id,
                                                StageName,
                                                Renewed_From__c
                                        FROM    Opportunity
                                        WHERE   Renewed_From__c IN : oppys];

    System.debug('Opps to Cancel is:: ' + oppsToCancel);

    updateOpps(oppsToCancel);
}

public static void updateOpps(List<Opportunity> oppsToCancel)
{
    for(Opportunity oppy : oppsToCancel)
    {
        oppy.StageName = 'Cancelled';
    }

    update oppsToCancel;
}
}
  • is that any debug is there with the executing user name with a valid date range? – Santanu Boral Jun 2 '17 at 20:46
  • Yes, there is a debug and it spits out results but it doesn't have anything in the log related to the above. I did Ctrl +F to search for keywords and nothing. – Dan Wooding Jun 2 '17 at 20:48
  • is that log is truncated? – Santanu Boral Jun 2 '17 at 20:49
  • are you using isRecursive variable only in this method? I think before of this you are not getting the log. It may be true from other ways and it is not entering in after update – Santanu Boral Jun 2 '17 at 20:51
  • it's not truncated, I'm actually using 5 total with 4 before the cancelAutoRenewal so I had assumed it would hit each one and then after set the recursive to true. – Dan Wooding Jun 2 '17 at 20:56
1

If you have used isRecursive variable in some other method, like before insert or after insert and same isRecursive you are using in this afterUpdate trigger then possibly it is getting set as true.

So below code will not call cancelAutoRenewal method and hence you will not receive any logs.

if(!isRecursive)
{
        cancelAutoRenewal(oldMap, newMap);
        isRecursive = true;
}
| improve this answer | |
  • It was actually I had the code in after update, when I changed it to before update it worked as expected. – Dan Wooding Jun 5 '17 at 14:40
  • actually before update has a less chance of being recursive. nicely fixed by you – Santanu Boral Jun 5 '17 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.