I have a custom home page narrow component i.e. My Component that have the following code in it to show my custom VF Page in an iframe


<style>#sidebarDiv .sidebarModule .sidebarModuleBody{    padding:0px;}</style><iframe style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; WIDTH: 200px; HEIGHT: 290px; BORDER-TOP: medium none; BORDER-RIGHT: medium none" src="/apex/samplePage"></iframe>

In my VF Page, I have a drop down list to show on the page. User can select different values from the pick list and it shows greetings based on the value (for example).

The issue is:

Whenever, the page refreshes or user goes to a different component in the SFDC, the home page narrow component gets refreshed as well, and the value for the pick list is set to the default value.

Need: I want it to retain the last selected value that use had it in the pick list, instead of setting it again to default value.

My thoughts:

I was thinking to get the reference to last selected value and pass it as a parameter in iFrame to my VF Page and have VF Page read this value in the beginning and set the value of the pick list.

How can I get the reference to the last selected value of the pick list in home page narrow component code? (listed above) Is it possible to retrieve the value of the selected pick list? If Not, then what should I be doing in my VF Page to ensure I always set the value to the last selected value, instead of the default value.

Following is the sample code

<!-- Page: -->

    <apex:page controller="sampleCls" showHeader="false" >
        <apex:form >

            <apex:selectList value="{!countries}"  multiselect="false" size="1" >
                <apex:selectOptions value="{!items}"/>

            <apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/>
     <apex:outputPanel id="out">
            <apex:actionstatus id="status" startText="testing...">
                <apex:facet name="stop">
                    <apex:outputPanel >
                        <p>You have selected:</p>


/* Controller: */

public class sampleCls {
    public String countries{get;set;}

    public PageReference test() {
        return null;

    public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('US','US'));
        options.add(new SelectOption('CANADA','Canada'));
        options.add(new SelectOption('MEXICO','Mexico'));
        return options;

    public String getcountry() {
        return countries;


screen shot

enter image description here

enter image description here

2 Answers 2


Faisal, Make sure that assign the pick list value in your VF page to your variable and in your controller assign that value to the custom setting. In addition, try to user the fully qualified variable name in your code with namespace. Something that could be an issue.

HTH Kashi


You could use some Javascript to set cookies and whatnot. But it's bit naive, will get wiped out whenever user clears cookies, they expire or he changes the browser... And might give funny results when system administrator uses "Login As".

  1. Go to Setup -> Develop -> Custom Settings, make new one (type = hierarchical). I've called mine "Country" (I don't care, it's my developer edition SF; you should pick something more meaningful and avoid clashes with existing objects).
  2. Add new text field to this setting (pity we can't add picklists).
  3. Create the class & VF page:

    public class CountryPicker{
        public Country__c c {get;set;}
        public CountryPicker(){
            // http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_System_HierarchyCustomSetting_getInstance.htm
            c = Country__c.getInstance();
        public void save(){
            upsert c;
    <apex:page controller="CountryPicker" showHeader="false" sidebar="false">
    <apex:form >
        <apex:selectList value="{!c.Country__c}"  multiselect="false" size="1" >
            <apex:selectOption itemValue="" itemLabel="- None -"/>
            <apex:selectOption itemValue="Canada"/>
            <apex:selectOption itemValue="Mexico"/>
            <apex:selectOption itemValue="USA"/>
        <apex:commandButton action="{!save}" value="Select" />
  4. Verify the value was set by going to the Custom Settings' definition and clicking "Manage". Try also logging in in different browser.

  5. In every other page / class where you'll need this custom setting's value for this user, reference it with $Setup.Country__c.Country__c (that's object name.field name although I'm not sure it won't return the Org-level setting if none other is present) or use the getInstance() in Apex to be sure you're retrieving and updating the value for "this" User.

Things to improve: move the picklist values to custom labels so they can be translated. Or maybe display the picklist of another object (where you already have the countries listed) and just cheat during saving by copying the value to the cust. setting.

  • hey eyescream im follow your steps but there is one issue im getting : login as admin first and try and everything works, and then login as a user and try and it doesn't work. and give exception error system.security.NoAccessException: Update access denied for Country__c here is my unmanaged pacakeg url can you check it and give me the solution ?
    – Faisal
    Commented Feb 7, 2014 at 19:42

You must log in to answer this question.

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