I am trying to assertEquals my test data's OwnerId against a picklist value's corresponding ID, but I don't know how to do the latter. Basically I want to know how to use Apex to grab the Id of a picklist value so I can compare it to my test data's OwnerId for testing.

System.assertEquals("The Id of the value of 'Analytics Support Team' picklist value", analyticsTicket.OwnerId);

Pretend that the part in quotes is the ID coming from the picklist. Please help.

2 Answers 2


I poked around and figured it out. We use process builder which maps to a queue, so I just grabbed the associated queue Id and compared it to my test data's ownerId

// check Owner ID assigned to Queue 'queueName'
// get QueueId of 'queueName' queue value:
string queueId = [select Id from Group where Name = 'queueName' and Type = 'Queue'].Id;
//check QueueId == OwnerId
System.assertEquals(queueId, testdata.OwnerId); 

So, I'm not that familiar with Apex relative to other parts of Salesforce, but I'd like to point out that picklist values default to having the same IDs as their labels. So in the likely event your picklist is formatted as a first name and a last name, as opposed to a 15- or 18-digit alphanumeric hash, you might actually have to try to compare the owner name to the picklist value instead.

So that'd look something more like the following:

analyticsTicket.Owner.FirstName & " " & analyticsTicket.Owner.LastName

Or, in the full formula,

System.assertEquals('The Id of the value of "Analytics Support Team" picklist value', analyticsTicket.Owner.FirstName & ' ' & analyticsTicket.Owner.LastName);
  • N.B. Apex string constants are enclosed in single quotes
    – cropredy
    Apr 12, 2023 at 22:26

You must log in to answer this question.

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