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
Mikko4Mikko4 

ISCHANGED in Apex

Hi,
 
In formulas you can use ISCHANGED function. Is there a similar method in Apex or is there some recommended design pattern for checking if a field value has changed in after update event?
 
How about ISNEW function?
 
Thanks!
Best Answer chosen by Admin (Salesforce Developers) 
MVJMVJ
Look at the Trigger.new and Trigger.old.  the .New has the current value the .Old will have the previous value.

You can compare them to see if a filed has been changed.


All Answers

Mikko4Mikko4
I noticed that ISNEW could be checked with Trigger.isInsert, right?
MVJMVJ
Look at the Trigger.new and Trigger.old.  the .New has the current value the .Old will have the previous value.

You can compare them to see if a filed has been changed.


This was selected as the best answer
edward scott 10edward scott 10
I am trying to do something similar. I have a trigger that makes a lead goes through the lead assignment but it only needs to happened if the status was changed to open. I see you or using .new and .old but how do I use that to check to see if a field value changed?
Shubham guptaShubham gupta
You can store the first Trigger.new & Trigger.old in Different list write your logic in If block condition like:-
if (newList.status != oldList.status && newList.status == "Open"){
}

Please mark it best answer if it helpfull.

Thanks,
Shubham