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
Timmy AhluwaliaTimmy Ahluwalia 

casting

Hi 
i have created the dynamic query where I have the record id, using the schema i have built the database.query, i am unable to get the values out of this query, 
if(dfr.isNameField()){
                 query = 'SELECT Id, ' +dfr.getName()+ ' FROM ' +myobj+ ' WHERE Id =:myId';
            }
list<sobject> query = database.query(query);
for(sobject s: query){
// want ot extract he value of the Name
}
can not do the casting.
Help to solve this.
Thanks
Has NahHas Nah
Does your query return any results if you run it in the query editor? is dfr.isNameField() == TRUE? 

If your function is exposed in the UI, I highly recommend sanitizing it using escapeSingleQuotes method to defend against SOQL Injections. Also it is advised to rename the list query to something more meaningful like results.
Timmy AhluwaliaTimmy Ahluwalia
Yes query is running but I can not fetch the values.