function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SKriLLSKriLL 

How to dynamcially build an object

How do I do something like this... Obviously fieldsetmemeber isnt the same as field, but it was the closet thing I could find to illistrate my point.  I want to be able to build an object dynamically even if the numbers or names of fields changes.  I could query the object and get a list of strings that are the names of the fields... but how do I turn that into a field reference?

for(Schema.FieldSetMember f : ObjectType.Custom_Object__c.FieldSets.Field_Set.getFields())
        {
            obj.f = datamap.get(f.getLabel());
        }

for(String s : ListOfFieldsNames)
{
   obj.s = datamap.get(s);
}

Bitcoin reward for a correct answer :)