1

I have picklist value.I have used dynamic picklist for this.I disabled it for some profile.When I create/edit/save for the profile users those can edit this field is coming good.The record getting savedc correctly.But when I am trying to edit the record from the user those can only see the disabled profile.Whatever value i have save only default value is coming.Please help.

//class

 public String selectedValue {get;set;}
        public List<SelectOption> getvalue()
        {
          List<SelectOption> options = new List<SelectOption>();

           Schema.DescribeFieldResult fieldResult =object__c.Field__c.getDescribe();
           List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();

           for( Schema.PicklistEntry f : ple)
           {
              options.add(new SelectOption(f.getLabel(), f.getValue()));
           }    
           return options;
        }
public pagereference saveRecord(){
..............
  obj.TradeAreaSuperNm__c=selectedValue;
insert obj;
}

//vf page

 <apex:pageBlockSectionItem >
          <apex:outputLabel value="picklist"/>
          <apex:selectList id="countries" value="{!selectedValue}" disabled="{!$profile='custom profile'}" size="1" multiselect="false">
              <apex:selectOptions value="{!value}"/>
          </apex:selectList>
   </apex:pageBlockSectionItem>
2
  • Well if they cannot edit it what do you expect to happen other than the default value being saved. I am confused???
    – Eric
    Dec 6, 2014 at 5:04
  • @Eric The field Should be readonly to the user.they can edit the value.But they are supposed to see the value that is saved by other user. Dec 6, 2014 at 5:06

1 Answer 1

1

Still not sure because you say in your comments:

Should be read only to the user. they can edit the value"

But, the issue you are having regarding showing the current field value to the user is due to the fact that you are not setting the value of selectedValue if the field has a value so change it to this:

Since you do not show all your code I do not know the property names of the record holding the existing data so you will have to update accordingly

public String selectedValue {get;set;}
        public List<SelectOption> getvalue()
        {
          List<SelectOption> options = new List<SelectOption>();

           Schema.DescribeFieldResult fieldResult =object__c.Field__c.getDescribe();
           List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();

           for( Schema.PicklistEntry f : ple)
           {
              options.add(new SelectOption(f.getLabel(), f.getValue()));
           }    

           selectedValue = {THERECORD}.Field__c; //Replace this with the property name of the record you are getting
           return options;
        }

You must log in to answer this question.

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