+ Start a Discussion
Ankit AroraAnkit Arora 

Fetch SObject.name

 

 Looking for a workaround to fetch name from sObject record like I have 

List<Sobject> sObj = Database.Query(dynamicQuery) ;
for(SObject obj : sObj)
{
      //I can do this
      System.debug(' :::::::: ' + obj.Id) ;
     // Looking to do this
     System.debug('::::::::::::: ' + obj.Name) ;
}

 

I know the SObject name lets say account but I do not want to type cast mt result like this

List<Sobject> sObj = Database.Query(dynamicQuery) ;
for(SObject obj : sObj)
{
     Account acc = (Account)obj ;
}

 

Any help regarding this would be appreciable

Thanks
Ankit Arora

 

Best Answer chosen by Admin (Salesforce Developers) 
SuperfellSuperfell

sobj.get('Name')

All Answers

SuperfellSuperfell

sobj.get('Name')

This was selected as the best answer
Ankit AroraAnkit Arora

I am such a stupid...... That really helped me. Thank you so much for the reply.

 

 

Thanks
Ankit Arora

 

 

 

Allie Cichocki 4Allie Cichocki 4
I'm also stupid and couldn't think of this. Thanks 4 the help! :-)
DEV_CGDEV_CG
List<Sobject> sObj = Database.Query('select id from Account');
system.debug(sObj.get('Name'));
am unable to fetch the name of sObject...
Method does not exist or incorrect signature: void get(String) from the type List<SObject>