Another Salesforce blog!!!

Salesforce, Apex

From the Object Api name retrieving the SObject


 Schema.SObjectType targetType = Schema.getGlobalDescribe().get(sObjectType);

 

or

id myid = 'a1a0n00000092jb';  
String sObjectType = ((Id)myid).getSobjectType().getDescribe().getName();

public void from_string_object_name_to_sObject()
{
  Schema.SObjectType targetType = Schema.getGlobalDescribe().get(sObjectType);//From the Object Api name retrieving the SObject
  Sobject Object_name = targetType.newSObject();
}

Leave a Reply

Your email address will not be published.

*