+ Start a Discussion

Constructor not defined: [SObject].<Constructor>()

Hi All,

I get the Below Error When I Initialise an S Object Instance. Could Some one Please let me know how I can Initialise it.

Public Sobject NewSObject = New SObject(); 

Error: Constructor not defined: [SObject].<Constructor>()

Thanks and Regards,
Best Answer chosen by uat_live1.3903047664538198E12

All Answers

Anoop yadavAnoop yadav
This was selected as the best answer
Iqrar AhmedIqrar Ahmed
Hi Uat_Live,

You can initialize dynamic sobject in following way

You can use the following code to create an SObject dynamically:

sObject sObj = Schema.getGlobalDescribe().get(ObjectName).newSObject() ;

where ObjectName is can be a name of any object like contact,account,opportunity

Best Regards
Senior Salesforce/.Net Developer