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
mavsmavs 

picklist in PageBlocktable

We have a picklist field on Account called status__c.

 

since SFDC does not respect recordtype for picklist in apex:inputfield,  we are planning to go for selectList.

 

Question:

1. We will need to populate/default the picklist value to what ever value was there on the Account record. (this needs to be done for all the records in the pageblocktable. If it would have been one then it will be easier. Sinc ethis is dynamic not sure how to achieve this.)

 

2. And when Save button is clicked we need to capture each select list Value to the controller.

 

We need some help on how to achieve the above two.

 

Please advise

 

PageBlockTable

Account Record

Status

ABC1

Good   (This was value on Account ABC1). This will be picklist prepopulated with Value Good

ABC2

--Select--  (No value on the Account. User have to select for this record). This will be Picklist, since there is no Value User can select

 

<apex:pageBlockTable value="{!Account_Results}" var="eve" > <apex:column headervalue="Status"> <apex:selectList value="{!status}" required="true" multiselect="false" size="1"> <apex:selectOptions value="{!items}"/> </apex:selectList> </apex:column> </apex:pageBlockTable> Public class my_controller( { public List<SelectOption> getItems() { options.add(new SelectOption('--Select--','--Select--')); options.add(new SelectOption('Good','Good')); options.add(new SelectOption('Do not recommend',Do not recommend')); options.add(new SelectOption('Fair','Fair')); options.add(new SelectOption('Very Poor','Very Poor')); return options; } List<String> AcctIds= new List<String>(); List<Account> account_records= new List<Account>(); for(Account ac:[Select Id,status from Account where Id IN:AcctIds]) { account_records.add(ac); } Public List<Account> getAccount_Results() { return account_records; } }

 

 

 

 

bob_buzzardbob_buzzard

This sounds to me like a prime candidate for wrapper classes.  Rather than backing your pageblocktable with an array of Account records, create a custom wrapper class that holds all the information for a single line in the table - this would include the valid selectoptions plus the array of strings to capture the chosen items (pre-populated as required). 

 

The getAccount_Results would create the list of wrapper objects based on the accounts, record types etc. You can then change your page to iterate the list of wrapper objects and pull the selectlist and selectoptions value from the wrapper object.