+ Start a Discussion

How to dynamically construct an if condition for fields based on custom setting?

Hi All,
I have a requirement where in I have to construct some if conditions dynamically.
1) I have custom setting 'Object Fields'  where in I give the fields that are to be synced.
2) I have class where I have a logic to sync 2 objects.
3) Inside the class, I need to have the logic to sync the fields on both the objects based on custom setting.

I have written the logic for existing fields, But I'm not sure if there is a easy way to handle if a new field is created.
Sample Code Snippet:
obj2.field1__c = obj1.field1__c;
 obj2.field2__c = obj1.field2__c;
As the above example says, I am able to handle for existing fields field1__c & field2__c, but not sure on how to handle if a new field is created 'field3__c'.
Any pointers or suggestions are highly appreciated.
Alain CabonAlain Cabon

Why don't you have used a fieldset instead of a custom setting?

The fieldsets are used for dynamic forms (VFP) but you can use them for anything with a dynamic list of field in apex.



User-added image