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
Pablo LamasPablo Lamas 

isAfter is not triggering.

So I have created a trigger and a trigger handler class, but I cant seem to make either of them trigger in an isAfter && isUpdate call. My updateInstallStatusDesign works fine when it is an isBefore && isUpdate but I need it at the isAfter && isUpdate call. 
Trigger
...
 	else if(Trigger.isAfter && Trigger.isUpdate)
    {
        OpportunityTriggerHandler.updateInstallStatusDesign(Trigger.old, Trigger.new);
        OpportunityTriggerHandler.createRedesignRecords(Trigger.new);
    }
...

TriggerHandlerClass
...
public static void updateInstallStatusDesign(List<Opportunity> originals, List<Opportunity> results)
    {
        updateInstallStatusToDesign(originals, results);
    }
    private static void updateInstallStatusToDesign(List<Opportunity> originals, List<Opportunity> results)
    {
        Map<Id, Opportunity> oldMap = new Map<Id, Opportunity>(originals);
        Map<Id, Opportunity> newMap = new Map<Id, Opportunity>(results);
        
        Set<Id> oppIdsWithStageChange = new Set<Id>();
        Set<Id> installIdsToGet = new Set<Id>();
        
        for(Id current : oldMap.keySet())
        {
            Opportunity oldOpp = oldMap.get(current);
            Opportunity newOpp = newMap.get(current);
            
            if(oldOpp == null || newOpp == null)
                continue;
            
            if(oldOpp.RecordTypeId != '012700000001Sgi' || newOpp.RecordTypeId != '012700000001Sgi')
                continue;
                            
            if(oldOpp.StageName != OpportunityStage.ContractApproved && newOpp.StageName == OpportunityStage.ContractApproved)
            {
                oppIdsWithStageChange.add(current);
                installIdsToGet.add(oldOpp.Installation__c);
                installIdsToGet.add(newOpp.Installation__c);
            }
        } 
        List<Installation__c> neededInstalls = [
               SELECT Id, Name, Install_Status__c
               FROM Installation__c
               WHERE Id IN :installIdsToGet 
        ];
        Map<Id, Installation__c> installationMap = new Map<Id, Installation__c>(neededInstalls);
        
        List<Installation__c> updateInstallations = new List<Installation__c>();
        
        for(Id current : oppIdsWithStageChange)
        {
            Opportunity oldOpp = oldMap.get(current);
            Opportunity newOpp = newMap.get(current);
            Installation__c oldInstall = installationMap.get(oldOpp.Installation__c);
            Installation__c newInstall = installationMap.get(newOpp.Installation__c);
            
            if(oldInstall == null || newInstall == null)
                continue;
                           
            if(oldInstall.Install_Status__c == InstallationStatus.SalesRepReview && newInstall.Install_Status__c == InstallationStatus.SalesRepReview)
            {
                updateInstallations.add(new Installation__c(
                    Id = oldInstall.Id,
                    Install_Status__c = InstallationStatus.Design
                ));
            }
        }
        if(updateInstallations.size() > 0)
        {
            update updateInstallations;
        }
    }
    
    public static void createRedesignRecords(List<Opportunity> results)
    {      
        Set<Id> installsNeedingRedesignRecord = new Set<Id>();     
        
        for(Opportunity curr : results)
        {
            installsNeedingRedesignRecord.add(curr.Installation__c);
        }
        
        List<Installation__c> installs = [
        	   SELECT Id, Name, Install_Status__c, of_Designs__c
               FROM Installation__c
               WHERE Id IN :installsNeedingRedesignRecord 
        ];
        Map<Id, Installation__c> allInstallMap = new Map<Id, Installation__c>(installs);
        
        List<Design__c> desingsToBeCreated = new List<Design__c>();
        
        for(Id installId : installsNeedingRedesignRecord ) 
        {
        	Installation__c currInstall = allInstallMap.get(installId);
            if(currInstall.of_Designs__c <= 1 && currInstall.OppStage__c == OpportunityStage.ContractApproved && currInstall.RecordTypeId == '012700000001Sgi' && currInstall.Install_Status__c == InstallationStatus.Design )
            {
            	desingsToBeCreated.add(new Design__c(
                	RecordTypeId = '01270000000MzZ8',
                	Installation__c = installId,
                	Design_Status__c = 'Revisions Needed',
                	Redesign_Reason__c = 'Building Department',
                	Revision_Number__c = '0'
       	     	));
            }
        }
        
        insert desingsToBeCreated;
    }
...