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
SocialRentSocialRent 

Trigger.new not returning updated information

I have a before update trigger that triggers successfully before an update of my custom object. The trigger looks to see whether a particular field is a particular value in this update. If so, then it will send out emails to particular people and update relevant fields in the object. 

I wrote test code which edits the particular field, then performs the update operation. I went into the debug logs to see what happened after this. The triggers goes off before the update (as it should), but when accessing the data retrieved from a SOQL query of Trigger.new, the data is not what the test code set to update, but what was originally there before the update, which is our problem. After the trigger has finished running, the field is now what it should have been after the update. 

I tried changing the trigger to be on after update, and trigger.new succesfully returns the correct value that my test code updated. However, because it is after update, I cannot modify the object.

Any ideas?

Starz26Starz26

have the trigger fire on before and after update

 

in the before edit your fields

 

in the after set out the email

 

if sending the email based on the before it will send the old values as the record has not been entered into the database yet.