Another Salesforce blog!!!

Salesforce, Apex

create instance of sobject dynamically


 public SObject getNewSobject(String t)
      {
	// Call global describe to get the map of string to token.
	Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();

	// Get the token for the sobject based on the type.
	Schema.SObjectType st = gd.get(t);

	// Instantiate the sobject from the token.
	Sobject s = st.newSobject();

	return s;
     }
     system.debug('///' + getNewSobject('Speaker__c') ); 

Leave a Reply

Your email address will not be published. Required fields are marked *

*