+ Start a Discussion
aaaaaaaaaaaaaaaaaaaaaa 

Custom settings used for comparing new and old values

Hi All,

I have to compare new and old values for few fields of a object.How can it be done using custom settings and used in apex class?
Can you help me few line of codes?
Thanks for helping
 
surasura
not very clear about your requirment but best way to compare old and new values of is through the use of Triggers .you can use the trigger .oldMap and trigger.newmap for this purpose
justin_sfdcjustin_sfdc
Hi,
Could you please elaborate why you are using custom settings here and what do you want to compare your values with?

Thanks!
aaaaaaaaaaaaaaaaaaaaaa
Hi sura/justin

Can i store 5 fields of an object in a custom setting and then use that custom setting to compare new and old value for a record using trigger?
I mean some 1-2 lines of code using custom settings which compares the new values for 5 fields not equal to old values for 5 fields.
justin_sfdcjustin_sfdc
I'm not sure if I got what you want exactly but this might be it.
Let's say that your custom settings name is Original_values__c; then;

List<original_values__c> custSettingList = [SELECT fields FROM original_values__c ];

for (object obj: Trigger.new) {
  for (original_values__c orgV: custSettingList) {
      if (obj.fieldName == orgV.fieldName) {
         //Perform some action here
      }
  }
}

Hope this helps!

Thanks!
David Holland 6David Holland 6
aaaaaaaaaaa

Why would you need a custom setting?

You can simply use trigger.New and trigger.OldMap to compare these values?