Friday, November 10, 2017

How to Convert String to sObject using Apex in Salesforce

Below is the sample code can be used to Convert String to sObject using Apex.

String str = 'Account';
sObject objct = Schema.getGlobalDescribe().get(str).newSObject();
objct.put('Name', 'My Account');
objct.put('Description', 'Description of My Account');
System.debug('sObject - ' + objct);
Below is the output of this code.

No comments:

Post a Comment