You can see in the example below that I'm using the OwnerId to check who's the owner of the case (it isn't pretty but it works).

But what if I have 100 users? Can someone suggest a solution for this?

List < Case > listOfCases = [SELECT Id, OwnerId FROM Case WHERE RecordTypeId IN: setRecordTypeIds];
for (Case c: listOfCases) {
    if (c.OwnerId == '005w0000004CjwgAAC') {
        //do something....

Is there a way to query the case owner name?

1 Answer 1


You should filter on a unique field, so I would avoid using Name. You can pull in fields like Username, Alias, etc. through your query using a Right Outer Join:

SELECT Owner.Username FROM Case
  • I tried to run it and this is the output I got: 15:52:50:010 USER_DEBUG [2]|DEBUG|Case:{OwnerId=00G20000001Wa8AEAS, Id=500w000000mYBkwAAG, RecordTypeId=01220000000FffjAAC} Can't see Owner.Username?
    – Json
    May 11, 2017 at 12:54
  • You can't get it by debugging the object itself. You would have to debug c.Owner.Username. @Dante
    – Adrian Larson
    May 11, 2017 at 12:54
  • I executed an anonymous window with the following: Case c = [SELECT Owner.Name FROM Case Limit 1]; system.debug(c); And then I got the output I posted above
    – Json
    May 11, 2017 at 12:58
  • 1
    @Dante I know. I'm saying when you debug(c) you're at the mercy of what Salesforce decides to log. When you debug(c.Owner.Username) you get exactly what you are looking for.
    – Adrian Larson
    May 11, 2017 at 13:00
  • Now I get it :)
    – Json
    May 11, 2017 at 13:02

You must log in to answer this question.

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