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.

SOQL Query to Get the CreatedBy and LastModifiedBy User Name


Below SOQL query can be used to get the CreatedBy and LastModifiedBy User Name


SELECT Id, Name, CreatedBy.FirstName, CreatedBy.LastName, CreatedBy.Name, LastModifiedBy.FirstName, LastModifiedBy.LastName, LastModifiedBy.Name FROM Object__c

Note: Object__c, you can replace for the object you want to get these data.