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

Dynamic fieldname with trigger.new and trigger.old
I need to look for changes in a list of fields in a record using a trigger. How can I reference the list of fields and append it to the trigger.new and the trigger.old references?
Below is code I've tried to use, but my variable "s" is not recognized. Thanks for any help you can provide.
Below is code I've tried to use, but my variable "s" is not recognized. Thanks for any help you can provide.
Map<Id, lda_Opportunity__c> MPPMap = new Map<Id, lda_Opportunity__c>(); list<Schema.SObjectField> FieldList = new list<Schema.SObjectField>(); FieldList.add(lda_Opportunity__c.Location__c); // Many more fields to add for (integer i=0; i < trigger.new.size(); i++){ for (Schema.SObjectField s : FieldList){ if (trigger.new[i].s != trigger.old[i].s){ MPPMap.put(trigger.new[i].Id, trigger.new[i]); } } }
You can use get method of sobject to accomplish this, Please try below mentioned code I made some correction in it: