Why am I getting an error when comparing trigger.oldMap with trigger.newMap on a boolean custom field?
I am trying to do a field change comparison in a trigger (trigger.oldMap vs trigger.newMap) on a boolean custom field I have in cases. This causes an incorrect signature error, when I do the exact same thing on other field types like text areas or picklist it works fine.
Is there a reason I can't do it on a boolean, and if so is there a workaround for it, I have tried with trigger.old.get(theField) but that gave the same error?
case oldStatus = Trigger.oldMap.get(c.Status); //picklist field type
case oldClosedBy = trigger.oldMap.get(c.Case_Closed_by_User__c); //boolean field type. give error "Method does not exist or incorrect signature: void get(Boolean) from the type Map" case oldQueue = Trigger.oldMap.get(c.Case_Queue_Name__c); //text area field type
Trigger.old is a Map of Case Id and Case instance.
To retrieve the field values, you will need to specify the ID as index and then the field name to get the corresponding values.
Trigger.oldMap.get(Case_ID).FieldName
Trigger.oldMap - A map of IDs to the old versions of the sObject records.
Trigger.newMap - A map of IDs to the new versions of the sObject records.
Trigger.old - A list of the old versions of the sObject records.
Trigger.new - A list of the new versions of the sObject records.
You may use Trigger.new, which is a list of Cases
for(Case newCase: Trigger.new){ //iterate through the list
//Get field values you need
System.debug('** Picklist : Case Status : ' + newCase.Status);
System.debug('** Boolean : Case Closed by User : ' + newCase.Case_Closed_by_User__c);
System.debug('** Text : Case Queue Name : ' + newCase.Case_Queue_Name__c);
//For the comparison, do:
//get old Case
Case oldCase = Trigger.OldMap.get(newCase.Id);
//Compare old and new value
if(oldCase.Case_Closed_by_User__c != newCase.Case_Closed_by_User__c){
//your logic here
}
}