I have two fields "Cost, Quantity"
to which I need to check if values are changed - In the future, some fields will get added to this list.
I don't want to change the trigger every time if new fields are added. So, I thought of adding a Custom Label with field API "Cost__c, Quantity__c"
and iterate this in Trigger to check Old and New values with single If condition. But this is not working as expected. Below is the sample code,
Custom Label : Account_History_Tracking_Fields
Values : Quantity; Cost
Sample Code
string HistoryFields = System.Label.Account_History_Tracking_Fields;
list<string> AccountHistoryFields = HistoryFields.split(';');
for(Account accx : Trigger.new)
{
Account oldAccount = Trigger.oldMap.get(accx.ID);
for(string AccField : AccountHistoryFields)
{
// I need something like below condition - which compares all custom label values with single If condition
//if(accx.AccField != oldAccount.AccField)
{
}
Is there a way to do this?