1

I have created a visualforce page with a dynamic picklist of users of a certain profile. I also have a report setup with a filter that needs a user to be specified.

I want to be able to select a user from the picklist, then click a link that goes to the report and at the same time passes the selected user into the url for the filter.

I think I need to setup an outputLink, but I need some guidance on how the pass the picklist value into the url. Below is the code for my dynamic picklist. Any help would be much appreciated.

<apex:page controller="dynamicpicklist" >
<apex:form >
<apex:sectionHeader title="Manager Portal" subtitle="Special Reports"/>
    <apex:pageblock >
        <apex:pageBlockSection title="Pollinator Inventory Reports" columns="1">
            <apex:outputlabel value="Pollinator" for="values"/>
            <apex:selectList value="{!pollinator}" size="1" id="values">
                <apex:selectOptions value="{!pollinatornames}"/>
            </apex:selectList>
        </apex:pageBlocksection>
    </apex:pageblock>
</apex:form>

public class dynamicpicklist
{

    public String processLinkClick { get; set; }
    public String pollinator{get; set;}

    public List<SelectOption> getpollinatornames()
        {
          List<SelectOption> options = new List<SelectOption>();
          List<User> pollinatorlist = new List<User>();
          pollinatorlist = [Select Id, Name FROM User ];
          options.add(new SelectOption('--None--','--None--'));
          for (User users : [SELECT Id, Name FROM User WHERE Profile.Name = 'Pollinators' AND IsActive = TRUE ORDER BY Name ASC]) 
              {
                  options.add(new selectOption(users.Id, users.Name));
              }
      return options;
        }
}
2
  • Can you please paste the URL for your report? Commented Mar 25, 2014 at 4:37
  • Sure it's /00O90000005uq8o?pv2={PICKLIST VALUE HERE}&pv3={PICKLIST VALUE HERE}
    – Ben
    Commented Mar 25, 2014 at 7:27

1 Answer 1

1
<apex:outputLink value="/apex/destination?picker={!pollinator}">link</apex:outputLink>

The controller side for the same

String pickerstr=Apexpages.currentpage().getParameters().get('picker');
//code to parse into list again
 public static List<String> stringparse(String str){

    str=str.remove('(');
    str=str.remove(')');
    str=str.deleteWhitespace();
    List<String> lst=str.split(',');

    return lst;
}

List<String> pickers=stringparse(pickerstr);

Then you can use this list in query with 'IN' clause .

2
  • Thanks Mohith. I don't quite understand what you mean with the IN statement. Could you provide an example of the accompanying IN statement? Thanks
    – Ben
    Commented Mar 25, 2014 at 8:54
  • List<Account> lst=[Select Id,pickerfield from Account where pickerfield IN :pickers]; Commented Mar 25, 2014 at 9:04

You must log in to answer this question.

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