+ Start a Discussion
uat_live1.3903047664538198E12uat_live1.3903047664538198E12 

Create An Object Instance at Run time

Hi,

How to create an Object Instance with type Specified at run time in Salesforce.Can Anyone help me to solve this issue.
Best Answer chosen by uat_live1.3903047664538198E12
bob_buzzardbob_buzzard
You can do this using the system Type class:
Type t = Type.forName('ShapeImpl');

Shape myShapej = (Shape)t.newInstance();
more about the type class is available at : https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_type.htm#apex_System_Type_newInstance

All Answers

bob_buzzardbob_buzzard
You can do this using the system Type class:
Type t = Type.forName('ShapeImpl');

Shape myShapej = (Shape)t.newInstance();
more about the type class is available at : https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_type.htm#apex_System_Type_newInstance
This was selected as the best answer
uat_live1.3903047664538198E12uat_live1.3903047664538198E12
Thank You So Much,