function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sagar patil 13sagar patil 13 

How To Create Generic Class for SObject In apex code

Using a Sobject name(which will be String) I should able to access fields of that SObject.
Alex SelwynAlex Selwyn
You can use sObject describe to get all the field names of an sObject. If thats what you are looking for.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dynamic_describe_objects_understanding.htm
EldonEldon
Hi sagar,

Please try the below code,
 
String sObjectName = 'Contact';
Schema.SObjectType t = Schema.getGlobalDescribe().get(sObjectName);
SObject s = t.newSObject();
s.put('LastName', 'TestGeneric');
insert s;

Hope this helps.
Regards