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
Spoorti JoshiSpoorti Joshi 

database.query returns Ids of reference fields in the query and not the actual reference field values

Akhil TandonAkhil Tandon
database.Query returns a list of Sobject, you would have to cast it into appropriate object to fetch the field values.
Below is an example

List<sObject> lstSobj = Database.query('select id,firstname from contact limit 5');
for(sObject s : lstSobj)
    Contact C = (Contact) s;
    system.debug('*******' + '*******'+ c.FirstName);