I have a controller that queries users to be selected in a vf page. I want to write a test class to test the code. The problem is I can't seem to populate the selection in my test so that it goes through the code.

The controller grabs the options:

public void fetchusers() {
if (selectedAttendeeType=='Search Account Team'){
        Id accountId = account.Id;
        for (User npdUser: [SELECT Id, Name FROM User WHERE IsActive=true AND Id IN (SELECT User__c FROM NPD_Account_Team__c WHERE Account__c = :accountId OR Parent_Account__c = :accountId) ORDER BY Name ASC LIMIT 1000]){
            possibleNPDAttendees.add(new SelectOption(npdUser.Id, npdUser.name));

The vf page the user selects the value:

<apex:outputPanel rendered="{!IF(account.RecordType.DeveloperName!='Practice_Account', 'true', 'false')}">
  <input type="radio" id="accountTeamList" name="Attendee" value="Search Account Team" checked="true" onclick="setSelectedSearch(this.value);"/>
  <b><label for="accountTeamList">Search Account Team</label></b><br/>
  <input type="radio" id="allNPDList" name="Attendee" value="Search All NPD" onclick="setSelectedSearch(this.value);"/>
  <b><label for="allNPDList">Search All NPD</label></b>
<c:SL_SelectBoxes id="attendeeSelection" leftOption="{!possibleNPDAttendees}"

In my test class tha I am rebuilding from an existing test the developer just called the methods and didn't actually test anything.

callReport.selectedAttendeeType = 'Search Account Team';

I have some users created in the test class, so I thought of doing the following to grab my user created in test and assign it to the select option so it would mimic being selected by the user.

callReport.npdattendees.add(user1.id, user1.LastName);

However, I get this error:

Method does not exist or incorrect signature: [List].add(Id, String)

If I just add the Id I get:

Incompatible element type Id for collection of System.SelectOption

How can one test adding a selection value?

  • Did you get it working?
    – Adrian Larson
    Jul 15, 2016 at 19:24
  • Yes, and no I added the line which solved one chunk but didn't cover a different chunk which used the same logic, then I went to try something on the vf page and I got a totally different error than what I was looking at so now I'm just getting ready to punch walls.. Jul 15, 2016 at 19:38
  • Not advisable for your health or programming ability to punch walls.
    – Adrian Larson
    Jul 15, 2016 at 19:39
  • Well, if this resolved your errors, perhaps it should be considered close and you can demonstrate in a new post what you're trying to cover? This question isn't really phrased as asking about coverage so much as asking why you can't add SelectOption(s) to the List.
    – Adrian Larson
    Jul 15, 2016 at 19:39
  • right, I was stuck trying to get the value into the select option so technically closed. Jul 15, 2016 at 19:43

1 Answer 1


The reason you receive that error is because you omitted the constructor.

Instead of:

callReport.npdattendees.add(user1.id, user1.LastName);


callReport.npdattendees.add(new SelectOption(user1.id, user1.LastName));

You must log in to answer this question.

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