0

I have written this trigger on Account oject by using trigger handler class. The before insert part of the code is working , However the before update code is not working and I checked the same using debug statement also that the code flow is not at all going inside the before update trigger part. So request your help to understand what is going wrong.

Here is the trigger code:

trigger AccuntTrigger on Account (before insert) {

    if(trigger.isInsert && trigger.isBefore){
        AccountTriggerHandler.beforeInsert(Trigger.new);
    }
    
    if (trigger.isUpdate && trigger.isBefore ){
        AccountTriggerHandler.beforeUpdate(Trigger.new, Trigger.oldMap);
    }
}

And here is the triggerHandler code:

public with Sharing class AccountTriggerHandler{

    public static void beforeInsert(List<Account> accountlist){
        for(Account accrec:accountlist){
            if (accrec.Industry=='Government' && accrec.Type=='Healthcare'){
                accrec.AnnualRevenue=1000000;
            }
        }
    }
    
    public static void beforeUpdate(List<Account> acclist, Map<Id, Account> accmap){
        for (Account acc:acclist){
            acc.Fax='30';
        }
    }
}

1 Answer 1

0

Your DML event list doesn't include "before update", so the trigger won't fire on "before update". Change the first line of code:

trigger AccountTrigger on Account (before insert, before update) {
1
  • Thanks for helping..it worked Commented Dec 22, 2022 at 11:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .