1

Due to some performance issues, I plan to migrate the Record-Triggered flows to the Apex trigger code.

I wrote all the criteria logic and updated the records in the Before Insert and BeforeUpdate functions in trigger But here. i have confusion about writing logic based on the evaluation mentioned in the flow. Some of the flows has "Evaluate the rule when a record is created, and every time it's edited" and some of them mentioned as " Evaluate the rule when a record is created, and any time it's edited to subsequently meet criteria". How to migrate this evaluation logic in the apex trigger?

1 Answer 1

1

Evaluate the rule when a record is created, and every time it's edited" means irrespective of the old values if the record meets the criteria the trigger should execute . For The condition can as be as below.

if((Trigger.isinsert || Trigger.isupdate) && Acc.Rating=='Hot'){

//Some logic
}

The above logic will work when ever the record is created or updated it check the condition and if that satisfies the logic will execute irrespective of old value.

For " Evaluate the rule when a record is created, and any time it's edited to subsequently meet criteria" means the logic should only execute when the condition is not meet earlier and the change to done on that record to meet the criteria. Find the below example for the same.

for(Account acc:Trigger.new)
{
   Account oldAccount= Trigger.oldmap.get(acc.id)

    if((Trigger.isupdate) && Acc.Rating=='Hot' && oldAccount.Rating!='Hot){
    
    //Some logic
    }
}

which means the logic will execute if the field old value is not hot and new value is hot.

You must log in to answer this question.

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