2

If I have a list of strings like so:

String[] fields = new String[]{'2', '3', '4', '6', '7', '8', '9', '11', '12', '13', '14', '16', '17', '18', '19', '21', '22', '23', '24', '26', '27', '28', '29'};

How can I implement them in a loop to call different field names?

for (String f : fields) {
    Lead.Custom_Field_' + f + '__c' = 'whatever';
}

Is this even possible in Apex? Thanks.

1 Answer 1

4

You can use the generic sObject type:

sObject myLead = new Lead();

for (String f : fields)
{
    myLead.put('Custom_Field_' + f + '__c', 'whatever');
}
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .