You need to sign in to do that
Don't have an account?

Compare trigger Not Working
Hello,
I am trying to compare the New value in a field which is a string and if it contains 'NO CHANGE' in it, then I would want to replace it by the Old Value. Below is my code. It seems to be not considering Contains expression as it it taking NO CHANGE but not a scentense where NO CHANGE is present. like THIS. HAS NO CHANGE. Below is my code in Before Update
Old Record - This is New
New Record - this is new - NO CHANGE
Trigger fires and then changes to Old Record - This is New
What i am I doing wrong here?
I am trying to compare the New value in a field which is a string and if it contains 'NO CHANGE' in it, then I would want to replace it by the Old Value. Below is my code. It seems to be not considering Contains expression as it it taking NO CHANGE but not a scentense where NO CHANGE is present. like THIS. HAS NO CHANGE. Below is my code in Before Update
Old Record - This is New
New Record - this is new - NO CHANGE
Trigger fires and then changes to Old Record - This is New
for(sObject newRecobj: Trigger.new){ myObject__C newRec = (myObject__C) newRecObj; SObject oldRecObj = Trigger.oldMap.get(newRec.Id); myObject__C oldRec = (myObject__C) oldRecObj; if('NO CHANGE'.contains(newRec._NOTE__c) && !string.isBlank(oldRec.NOTE__c) && !'NO CHANGE'.contains(oldRec.NOTE__c)){ newRec.NOTE__c = oldRec.NOTE__c; } }
What i am I doing wrong here?
If I understand correctly what you mean then you should do the check the other way around. Now you are checking if the string 'NO CHANGE' contains the value of your field. So what you want to do is newRec._NOTE__c.contains('NO CHANGE')
All Answers
If I understand correctly what you mean then you should do the check the other way around. Now you are checking if the string 'NO CHANGE' contains the value of your field. So what you want to do is newRec._NOTE__c.contains('NO CHANGE')