You need to sign in to do that
Don't have an account?

How to dynamically create an instance for an Object in Constructor of a Controller?
Hi All,
How to dynamically create an instance for an Object in Constructor of a Controller when that Object is selected from the picklist in VF page.
I think you are looking after this
public String filterID{get;set;}
public ConstructorName(){
Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
/* Get the token for the sobject based on the type. */
Schema.SObjectType st = gd.get(filterID);
/* Instantiate the sobject from the token. */
Sobject s = st.newSobject();
}
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks
Hi,
There is method to create an instance of Sobject :
public static sObject createObject(String typeName) {
Schema.SObjectType targetType = Schema.getGlobalDescribe().get(typeName);
return targetType.newSObject();
}