I have a simple trigger that runs on Account update, and the only logic is a check to whether or now BillingPostalCode changes or not.
This is my code:
trigger ZipCodeUpdated on Account (before update) {
for(Integer i=0; i<Trigger.new.size(); i++){
if(Trigger.new[i].BillingPostalCode != Trigger.old[i].BillingPostalCode){
ZipCodeUpdatedHelper.InitialCheck(Trigger.new, Trigger.old);
}
}
}
I'm not sure how the test class should look like, so any help would be appreciated.
Trigger.oldMap
context variable to access the old record (allowing you to usefor(Account acct :trigger.new)
instead offor(Integer i=0; i<Trigger.new.size(); i++)
). You also probably don't want to be calling yourZipCodeUpdatedHelper.InitialCheck()
method on every iteration (and not passing all trigger records to it when you do). Having your loop create Lists of records to process, and then calling your method outside of the loops (passing the Lists your loop populated) is a better approach.