I need to use dynamic fields in a for loop so that i can pick up the values from different field on insertion of an object accordingly.
Below mentioned are the fields which needs to be dynamically accessed.
Is there a way where we can use something like Target_Name_[i]__c
in the loop so that on every iteration it picks up the respective field value?
Best Answer
The
SObject
class has dynamicget
methods that allow you to specify a string. You could, for example, do something like: