I have one requirement, Actually using below code i save object record in database dynamically.

Schema.SObjectType targetType = Schema.getGlobalDescribe().get(strFieldName);
SObject myObj = targetType.newSObject();
insert myObj;

Note: using above code related object record only created.

But I gave some fields information here but those fields information is not saved in this record

How to save fields information also related object record Dynamically?

1 Answer 1


It works like a map:

sObject myObject = new Account(); // in your case your target type, this is just an example
myObject.put('Name', 'Test Account'); // use put(fieldAPIname, value)

Sometimes your might need to cast your values to the corresponding field types though.

Also, check field level security on those fields and make sure they are visible for the current profile.

  • Yaa I gave field editable permission also dynamically through coding.Here my object and object related fields dynamiacally add to visualforce page. Commented Jul 14, 2014 at 7:00
  • I'm afraid I don't understand what exactly you're trying to achieve... Commented Jul 14, 2014 at 23:24

You must log in to answer this question.

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