function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jyovasjyovas 

Populating picklist from table values

hi I have a custom page for Opportunity and have two fileds Type and Portfolio of type PickList. As this list can grow from populated records I want to populate this picklist from table values . I am able to achive that and able to save the record But when I edit the saved record all other fields are populated except the Picklist fields. How does Salesforce store picklist in actual record as Text or ID ?

 

page

 

 <apex:actionRegion > 
          <apex:selectList value="{!typeExt}" size="1" id="typeList">
            <apex:selectOptions value="{!TypeOptions}"/>
            <apex:actionSupport event="onchange" rerender="portfolioList" />
           </apex:selectList>
       </apex:actionRegion> 

 <apex:PageBlockSectionItem >

 

 <apex:outputLabel value="Portfolio" />
        <apex:selectList size="1" id="portfolioList" value="{!portFolio}">
        <apex:selectOptions value="{!PortfolioOptions }"/>
        </apex:selectList>
       </apex:PageBlockSectionItem>

 

Controller

public List<selectOption> PortfolioOptions {

get {
        List<selectOption> types =new List<selectOption>();
        types.add(new SelectOption('','- None -'));
        if(typeExt != NULL ) {
                OpportunityType__c opType = [select OpportunityVehicle__c from OpportunityType__c  where id = :typeExt ];
             for (Portfolio__c port : [select Name from Portfolio__c where OpportunityVehicle__c= :opType.OpportunityVehicle__c]){
              types.add(new SelectOption(port.id, port.Name ));
              }
          }
          else{
            for (Contact c : [select lastname from contact c where lastname ='Jobs' ]){
              types.add(new SelectOption(c.id,c.lastname ));
              }
          }
                 return types;
 }        

private set;
}

public List<selectOption> TypeOptions {
get {       
    List<selectOption> types =new List<selectOption>();
    types.add(new SelectOption('','- None -')); 
    for( OpportunityType__c opt: [select Id, Name,OpportunityVehicle__c from OpportunityType__c])
   {
      types.add(new SelectOption(opt.Id ,opt.Name));
   }   
     return types;
 }
 private  set;
 }

 

What do i have to do to retain the saved values in Edit page ?

 

BTW I am saivng the picklist value as TEXT  . Is it right ?

 

public void SetportFolio(string s){
    this.portFolio =s;
    Portfolio__c port = [select Name from Portfolio__c where id =:this.portFolio];
    this.oppor.Portfolio__c = port.Name;
}

Thanks,

John

bob_buzzardbob_buzzard

You should be okay saving the picklist value as a string.  

 

As you are backing the selectlist with the porfolio field, you'll need to make sure that you set that field up correctly with the information from the opportunity prior to the getter being called - possibly in your controller constructor.