You need to sign in to do that
Don't have an account?
URGENT: Compare old and new value
I have to write a trigger for checking the last modified date of an object before update. I need to compare the old value with the new value and if the new date is smaller, the trigger show be discarded (i.e. no update).
How to get both(old and new) values of a field?
Also, if the condition is true how to discard the trigger from updating?
Need Help.
Since you didn't say what the object is that you are running thee trigger on, I just used the generic term, 'sObject' in its place. Hopefully this makes sense!
You could also put this in an external class method and send the trigger.old and trigger.new as lists to it and then loop through based off of the trigger size.... as far as I know!
All Answers
Trigger.old and trigger.new return the old and the new values respectively.... write the update statement if the condition is true..
Thanks for the quick response.
Can you show them with some code examples?
Since you didn't say what the object is that you are running thee trigger on, I just used the generic term, 'sObject' in its place. Hopefully this makes sense!
You could also put this in an external class method and send the trigger.old and trigger.new as lists to it and then loop through based off of the trigger size.... as far as I know!
Hi,
You can check old value and new value from trigger.old and trigger.new respectively.
Check the code snippet below:-
trigger Accdata on accont(before update)
{
Account accOld = trigger.old[0];
Account accNew = trigger.new[0];
if(accOld.lastmodifieddate != accNew.lastmodifieddate){//YOUR BUSINESS LOGIC HERE...}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Thanks.