Does anyone know why this query does not show the LastModifiedByName and CreatedBy.Name even though I am explicitly asking for it?

List <Report> result = [SELECT Name, CreatedDate, CreatedBy.Name, LastModifiedBy.Name FROM Report];

In the output (running execute anonymous window), I see everything except for these items. But if I were to run it in the query editor in the developer console, it works fine. Am I missing something here?

Any help is appreciated. Thanks.

1 Answer 1


When using system.debug();, the data on related records is not shown. In other words, if you have any dot/period/full-stop to access the field in your query, you won't see it. That's just the way it works.

If you iterate through each result of the query and specifically system.debug(myReportRec.LastModifiedBy.Name);, you would see it.

If you serialize the results as JSON, and debug them, you'd see the related records as well.

  • How would I go about serializing the results as JSON?
    – apexdev
    Feb 14, 2022 at 20:17
  • 1
    @apexdev using JSON.serialize()
    – Derek F
    Feb 14, 2022 at 20:17
  • I'm doing it like this: List <Report> result = [SELECT Name, CreatedDate, CreatedBy.Id, CreatedBy.Name, LastModifiedBy.Name FROM Report]; for (Report stuff : result) { system.debug(JSON.serialize(stuff)); } But I'm still not seeing the names, only the ID's.
    – apexdev
    Feb 14, 2022 at 20:21

You must log in to answer this question.

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