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;
}
}
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