• Sushant Patil
  • NEWBIE
  • 10 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hi All,

I need to create an Instance of an Object at runtime. I change the ObjectType string at runtime in the below code.

String ObjectType = 'Cars__c';
Type t = Type.forName(ObjectType);
 sObject newObj = t.newInstance();
newObj.Name = 'test';
insert newObj;

I get an error like  "Compile Error: Illegal assignment from Object to SObject "

Anywere in the code I should not have the hardcoded APIs like Cars__c. I get all these from custom settings.Could someone please guide me.
Kindly also let us know the difference between SObject and Object.
Thanks and Regards,
Chirstwin