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
mng0827mng0827 

Apex trigger execution

Hi,

I have an apex trigger on Account which updates an Account field based on another Account field. Upon testing, it only triggers when I attempt to meet the criteria the second time. On the first attempt, it doesn't fire. Here's my code:


trigger UpdateHHIncome on Account (before update) {
           
         Account acct = trigger.new[0];
   
    {    if(acct.HH_Income_ID__c == 1){
           acct.Tax_Filing_Status_Peakfolio__c = 'Single';     
           acct.Household_Income__c = 'Up to $8,925';
        } else if (acct.HH_Income_ID__c == 2){
           acct.Tax_Filing_Status_Peakfolio__c = 'Single';     
           acct.Household_Income__c = '$8,926 - $36,250';
        } else if (acct.HH_Income_ID__c == 3){
           acct.Tax_Filing_Status_Peakfolio__c = 'Single';     
           acct.Household_Income__c = '$36,251 - $87,850';
        } else if (acct.HH_Income_ID__c == 4){
           acct.Tax_Filing_Status_Peakfolio__c = 'Single';     
           acct.Household_Income__c = '$87,851 - $183,250';
        } else if (acct.HH_Income_ID__c == 5){
           acct.Tax_Filing_Status_Peakfolio__c = 'Single';     
           acct.Household_Income__c = '$183,251 - $398,350';
        } else if (acct.HH_Income_ID__c == 6){
           acct.Tax_Filing_Status_Peakfolio__c = 'Single';     
           acct.Household_Income__c = '$398,351 - $400,000';
        } else if (acct.HH_Income_ID__c == 7){
           acct.Tax_Filing_Status_Peakfolio__c = 'Single';     
           acct.Household_Income__c = '$400,001 or more';
        } else if (acct.HH_Income_ID__c == 8){
           acct.Tax_Filing_Status_Peakfolio__c = 'Married filing jointly';     
           acct.Household_Income__c = 'Up to $17,850';
        } else if (acct.HH_Income_ID__c == 9) {
           acct.Tax_Filing_Status_Peakfolio__c = 'Married filing jointly';     
           acct.Household_Income__c = '$17,851 - $72,500';
        } else if (acct.HH_Income_ID__c == 10) {
           acct.Tax_Filing_Status_Peakfolio__c = 'Married filing jointly';     
           acct.Household_Income__c = '$72,501 - $146,400';
        } else if (acct.HH_Income_ID__c == 11) {
           acct.Tax_Filing_Status_Peakfolio__c = 'Married filing jointly';     
           acct.Household_Income__c = '$146,401 - $223,050';
        } else if (acct.HH_Income_ID__c == 12) {
           acct.Tax_Filing_Status_Peakfolio__c = 'Married filing jointly';     
           acct.Household_Income__c = '$223,051 - $398,350';
        } else if (acct.HH_Income_ID__c == 13) {
           acct.Tax_Filing_Status_Peakfolio__c = 'Married filing jointly';     
           acct.Household_Income__c = '$398,351 - $450,000';
        } else if (acct.HH_Income_ID__c == 14){
           acct.Tax_Filing_Status_Peakfolio__c = 'Married filing jointly';     
           acct.Household_Income__c = '$450,001 or more';
        } else if (acct.HH_Income_ID__c == 15){
           acct.Tax_Filing_Status_Peakfolio__c = 'Married filing separately';     
           acct.Household_Income__c = 'Up to $8,925';
        } else if (acct.HH_Income_ID__c == 16){
           acct.Tax_Filing_Status_Peakfolio__c = 'Married filing separately';     
           acct.Household_Income__c = '$8,926- $36,250';
        } else if (acct.HH_Income_ID__c == 17){
           acct.Tax_Filing_Status_Peakfolio__c = 'Married filing separately';     
           acct.Household_Income__c = '$36,251 - $73,200';
        } else if (acct.HH_Income_ID__c == 18){
           acct.Tax_Filing_Status_Peakfolio__c = 'Married filing separately';     
           acct.Household_Income__c = '$73,201 - $111,525';
        } else if (acct.HH_Income_ID__c == 19){
           acct.Tax_Filing_Status_Peakfolio__c = 'Married filing separately';     
           acct.Household_Income__c = '$111,526 - $199,175';
        } else if (acct.HH_Income_ID__c == 20){
           acct.Tax_Filing_Status_Peakfolio__c = 'Married filing separately';     
           acct.Household_Income__c = '$199,176 - $225,000';
        } else if (acct.HH_Income_ID__c == 21){
           acct.Tax_Filing_Status_Peakfolio__c = 'Married filing separately';     
           acct.Household_Income__c = '$225,001 or more';
        } else if (acct.HH_Income_ID__c == 22){
           acct.Tax_Filing_Status_Peakfolio__c = 'Head of household';     
           acct.Household_Income__c = 'Up to $12,750';
        } else if (acct.HH_Income_ID__c == 23){
           acct.Tax_Filing_Status_Peakfolio__c = 'Head of household';     
           acct.Household_Income__c = '$12,751 - $48,600';
        } else if (acct.HH_Income_ID__c == 24){
           acct.Tax_Filing_Status_Peakfolio__c = 'Head of household';     
           acct.Household_Income__c = '$48,601 - $125,450';
        } else if (acct.HH_Income_ID__c == 25){
           acct.Tax_Filing_Status_Peakfolio__c = 'Head of household';     
           acct.Household_Income__c = '$125,451 - $203,150';
        } else if (acct.HH_Income_ID__c == 26){
           acct.Tax_Filing_Status_Peakfolio__c = 'Head of household';     
           acct.Household_Income__c = '$203,151 - $398,350';
        } else if (acct.HH_Income_ID__c == 27){
           acct.Tax_Filing_Status_Peakfolio__c = 'Head of household';     
           acct.Household_Income__c = '$398,351 - $425,000';
        } else if (acct.HH_Income_ID__c == 28){ 
           acct.Tax_Filing_Status_Peakfolio__c = 'Head of household';     
           acct.Household_Income__c = '$425,001 or more';     
        } else{acct.Tax_Filing_Status_Peakfolio__c = null;
             acct.Household_Income__c = null;}
    }
}
EnreecoEnreeco
Can you post the test code?
mng0827mng0827
The trigger appears to work on time now. I did a research and found out that this is caused by a field update on a field also being used in the trigger. I deleted the workflow and made a trigger instead. Thanks for reaching out.