I have the user object in which I have defined a picklist field. The need for this is to allow certain users to only see certain records on a custom VF page. I need to get the selected picklist value for the user viewing the VF page and send to my apex controller to query a custom record. I am not sure how to proceed with this endeavour.


  • 1
    Can you also provide the code snippet that you have tried so far?
    – Jayant Das
    Jul 10, 2018 at 14:57

1 Answer 1


This is something you can accomplish within the Apex controller for your Visualforce page.

You'd query something like

User u = [SELECT My_Picklist__c FROM User WHERE Id = :UserInfo.getUserId()];

Then, you can use the value of u.My_Picklist__c to make choices about which sets of records you'd like to query and show for that user, even using the new switch construct:

switch on (u.My_Picklist__c) {
    when 'Value__one' {
        // Do something
    when 'Value__two' {
        // Do something

Be aware that your Apex controller will enforce sharing rules and visibility, if that's part of your objective, only if it is declared with sharing. Otherwise, you'll query records without regard for ownership, org-wide defaults, and sharing rules.

You must log in to answer this question.

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