![](https://www.infallibletechie.com/wp-content/uploads/2023/01/Convert-String-to-sObject-using-Apex-in-Salesforce-1024x576.jpg)
Schema.getGlobalDescribe().get().newSObject() can be used to convert String to sObject using Apex in Salesforce.
Sample code:
//Setting String str as Account
String str = 'Account';
//Casting String to sObject
sObject obj = Schema.getGlobalDescribe().get(str).newSObject();
obj.put('Name', 'Test');
obj.put('Description', 'Testing');
system.debug('obj is ' + obj);
Output:
![](https://www.infallibletechie.com/wp-content/uploads/2017/09/How2Bto2Bconvert2BString2Bto2BsObject2Busing2BApex2Bin2BSalesforce.png)