i want to fetch the record name using record id. below is my dynamic query

SObject record = Database.query('Select CaseNumber From ' + sObjName + ' Where Id = :subOrderId');

Could anyone please let me know how can i extract the CaseNumber alone from the above query.

  • 1
    SObject's have getter methods with which you can return fields. record.get('CaseNumber') doesn't work?
    – Raul
    Commented Feb 23, 2018 at 10:33
  • tried without quotes record.get(CaseNumber) so i was getting some errors. Now, its resolved, Thank you so much for your response.
    – Sab__Dev
    Commented Feb 23, 2018 at 10:38

1 Answer 1


For accessing fields from SObject use getter methods like:

// with String


// with Schema.sObjectField

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .