ads

Thursday, 30 August 2018

Convert String to sObject using Apex in Salesforce

Code Format:


//Setting String str as Contact

String str = '
Contact';

//Casting String to sObject

sObject objc = Schema.getGlobalDescribe().get(str).newSObject();
objc.put('LastName', 'Test');
objc.put('
AssistantName', 'Testing');
objc.put('Department', 'Testing');

system.debug('objc is ' + objc);

Output:


No comments:

Post a Comment