I have a long text area field which is on the page layout along with other fields. User is changing a picklist field but when trigger compares old and new values, long text are field is also detected as changed even when user has not made any changes to it. In the below code if condition is satisfied, when I check old and new records using get method and passing field API Name,
for(CustomObj__c req: trigger.new)
{
CustomObj__c oldreq = trigger.oldMap.get(req.Id);
String longtextareafieldAPIName = 'MyCustomField__c';
if(req.get(longtextareafieldAPIName) != oldreq.get(longtextareafieldAPIName) )
{
system.debug('changed field - ' + longtextareafieldAPIName);
system.debug('old value - ' + oldreq.get(longtextareafieldAPIName));
system.debug('new value - ' + req.get(longtextareafieldAPIName));
}
}
when I compare the system debug output of old and new value, they are exactly the same. Any reason why .get method is returning different values ?
Object
values. It might be different if you use the actualString
values.get
call, it was just a guess at what might be going on here.if(JSON.serialize(req.get(fieldName)) != JSON.serialize(oldreq.get(fieldName)))