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
Vivek ManchandaVivek Manchanda 

How to get all the data from the Account Rating pick list in custom VisualForce Application ?

I am trying to get the value from the Pick List  " Account Rating " in my VisualForce custom Application data like "HOT,WARM,COLD ".

I have made the Custom Controller through which I am trying to add new Account 's .

Now I want to Add new field in my Application that is Account Rating Pick List .
TehNrdTehNrd
I'm still a rookie when it comes to VF but I think this is what you have to do. Since you are using a custom controller I think you will need to essentially create this field from scratch. Also, apex doesn't currently support querying the metadata (future release I believe) so you will need to hard code the picklist(selectList) values.

Page:
Code:
<apex:form>
<apex:selectList value="{!AccountRating}" size='1'>
<apex:selectOptions value="{!items}"/>
</apex:selectList>
</apex:form>

 Controller:
Code:
String AccountRating;

public List<SelectOption> getItems(){
 List<SelectOption> options = new List<SelectOption>();
 options.add(new SelectOption('','--None--'));
 options.add(new SelectOption('Hot','Hot'));
 options.add(new SelectOption('Warm','Warm'));
 options.add(new SelectOption('Cold','Cold'));
 return options;
}

public void setAccountRating(String AccountRating){
 this.AccountRating = AccountRating;
}

public String getAccountRating(){
 return picklist;
}

 I also threw this together in notepad so it might have some syntax errors but it should be good.


Message Edited by TehNrd on 02-29-2008 01:18 PM
mtbclimbermtbclimber
Or just use the all powerful inputField as such:

Code:
<apex:page standardController="Account">
  <apex:form>
    <apex:pageBlock title="Rating">
      <apex:pageBlockSection>
        <apex:inputField value="{!account.name}"/>
        <apex:inputField value="{!account.rating}"/>
      </apex:pageBlockSecton>
    </apex:pageBlock>
  </apex:form>
</apex:page>

 


I too did not compile the above but it should give you a headstart.

Message Edited by mtbclimber on 03-02-2008 07:48 AM

Message Edited by mtbclimber on 03-02-2008 10:39 AM
PallavPallav
Hi,

I would like to know.. if there is any way we can get the values of picklist like Account ratings directly from Salesforce and populate the selctList control in our custom Visualforce page? rather then harcoding it or using the Standard controller??

Thanks in anticipation of your response.

regards
Pallav
Ron HessRon Hess
Not today.

This is a future feature, the ability to describe the field types, sizes, default pick lists given an object name.


mtbclimbermtbclimber
I think that request could actually be interpreted another way. You don't need to use the standard controller to get the benefit of inputField. You can return an Account (or collection of accounts) from your custom controller and the usage would be the same as that described in standard controller example above (assuming your controller has a getAccount() method).

Summary:

Today you would use inputField with a standard OR custom controller in apex to present a picklist for account.rating in a way that dynamically presents the picklist values managed under setup for that field.

If you want to use the picklist values in some other way, i.e. present all the values (not in an input), then you would need the ability to access describe in apex which is not available today as Ron suggests.