You need to sign in to do that
Don't have an account?
OnurK
oldMap and newMap in Class
Hi All;
I have a class runs after trigger. I need my class not run after an update when the certain field not updated. (I need my trigger runs after tax number changes) In trigger body it is possible to accomplish this with;
System.trigger.oldMap.get(c.id).Tax_Number__c != System.trigger.newMap.get(c.id).Tax_Number__c )
I can not add this code in a class. There must be some other way we can compare old value vs new value in a class. Can anyone help me with the issue I have?
Thank you very much for your help.
Yes you cannot add the code in the class. you have to do that filtering in the apex trigger and then pass only the qualified records to the class
All Answers
Yes you cannot add the code in the class. you have to do that filtering in the apex trigger and then pass only the qualified records to the class
You can try this in your trigger:
Trigger triggername on object (trigger conditions)
{
if(IsUpdate)
{
if(System.trigger.oldMap.get(c.id).Tax_Number__c != System.trigger.newMap.get(c.id).Tax_Number__c )
{
//do your stuff here
}
}
}
I hope this helps
Thank you SrikanthKuruvaSR,
This is what I thought as well.
Thanks j020,
I think we can not use the code you suggested in the class.
Ofcourse we can't use the code in class but it was ment for trigger only. You need to call the specific method from your trigger based on this condition.
Regards,
I have a class updates a field from Sales Representative field. I need trigger not run if the Sales Representative field not changed. ı tried something like this but I have another before case trigger test give error now.
Can you please help?
i see that you are doing a mistake in the code.
cs corresponds to trigger.new and you are comparing this again with the trigger.newMapinstead of trigger.oldmap. you should be doing something like following (changed System.trigger.newMap to System.trigger.oldMap)
Thank you very much for your response.