Can i dynamically assign a sobject field a value.?
Due to the poor data model setup of existing I am forced to do this
My issue is fieldname on object is stored at some other object.Say for eg i have a string fieldname where i store actualfieldname of the object.Now i want to update this field of the object as below
string fieldname = 'Name'
test__C c = new test__C();
c.fieldname = 'Hello';
This throws me an error.Is there any other way to achieve this?
Best Answer
Yes, that is possible (see also the documentation for all sObject methods):
Use
c.put(fieldname,'Hello')