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
DEV_CGDEV_CG 

unable to fetch Sobject name...( Account/contact /lead ) etc

List<Sobject> sObj = Database.Query('select id from Account');
system.debug(sObj.get('Name'));
i referred this link :https://developer.salesforce.com/forums/?id=906F00000008qYUIAY

am unable to fetch the name of sObject...and am getting below error
Method does not exist or incorrect signature: void get(String) from the type List<SObject>

 ireferred the one of the link of our forum,but its not working for me...could anyone help me
please refer below link 

 
Abdul KhatriAbdul Khatri
First if you need to get the name of the sObject you need to try this. Since the result return from the SOQL is List so you need to get the first element to do that
 
List<SObject> sObj = Database.Query('select id from Account');
system.debug(sObj[0].getSObjectType());

In this since you are referrring the Name (Field Name) which will give you the value of the Record no the Value of the SObject but you have not mention the Field Name in the SOQL.
system.debug(sObj[0].get('Name'));
So alter your SOQL Like this
 
List<Sobject> sObj = Database.Query('select id, Name from Account');
system.debug(sObj[0].get('Name'));

If you wanted to find for the entir list then use this
 
List<SObject> sObj = Database.Query('select id, Name from Account');
for(SObject sObjIns : SObj) {
	system.debug(sObjIns.get('Name'));    
}

I hope this will calrifies