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?


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. – user3149325 Jul 14 '14 at 7:00
  • I'm afraid I don't understand what exactly you're trying to achieve... – Boris Bachovski Jul 14 '14 at 23:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.