You need to sign in to do that
Don't have an account?
Nick Nelson 9
Apex - LastModifiedById, OldMap, NewMap, all return same value
I'm trying to write a 'before update' apex trigger that uses values from the oldmap of an object, but have been having issues. I have been using a text field on the object to test the LastModified values, but found that the new value, the oldmap value, and the newmap value are identical.
The code below shows what I'm talking about:
Any help would be appreciated, thanks.
The code below shows what I'm talking about:
trigger Example on Contact (before update) { for (Object o: trigger.new) { try { o.Description = 'Current LastModifiedBy: ' + o.LastModifiedById + ' \noldMap: ' + Trigger.OldMap.get(o.Id).LastModifiedById + ' \nnewMap: ' + trigger.newMap.get(o.Id).LastModifiedById; } catch (Exception e) {} } }Again: o.LastModifiedById, Trigger.OldMap.get(o.Id).LastModifiedById, and Trigger.NewMap.get(o.Id).LastModifiedById, all return the same value.
Any help would be appreciated, thanks.
Per https://salesforce.stackexchange.com/questions/120795/why-lastmodifiedbyid-in-trigger-new-gives-old-value
"System audit fields like LastModifiedById, LastModifiedDate, and SystemModStamp are not updated until later in the transaction. You shouldn't rely on any of those values being set, especially in a "before" trigger"
Also, you can still modify records in after triggers, you just have query them with a SOQL statement first.
I'm not sure what you are asking. Presumably you are trying to find out who modified the record previously and who's modifying it now.