Skip to content

Instantly share code, notes, and snippets.

@tyoshikawa1106
Created June 11, 2015 11:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tyoshikawa1106/e1ed8aff6a65a066dea6 to your computer and use it in GitHub Desktop.
Save tyoshikawa1106/e1ed8aff6a65a066dea6 to your computer and use it in GitHub Desktop.
<apex:page controller="PicklistEntryDemoController" sidebar="false" tabStyle="Account">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection columns="2">
<apex:pageBlockSection columns="1" title="選択リスト値取得">
<apex:outputPanel >
<ul>
<apex:repeat value="{!selectList}" var="item">
<li><apex:outputText value="{!item}" /></li>
</apex:repeat>
</ul>
</apex:outputPanel>
</apex:pageBlockSection>
<apex:pageBlockSection columns="1" title="複数選択リスト値取得">
<apex:outputPanel >
<ul>
<apex:repeat value="{!multiselectList}" var="item">
<li><apex:outputText value="{!item}" /></li>
</apex:repeat>
</ul>
</apex:outputPanel>
</apex:pageBlockSection>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
public with sharing class PicklistEntryDemoController {
public List<String> selectList {get; set;}
public List<String> multiselectList {get; set;}
public PicklistEntryDemoController() {
// 初期化
this.selectList = new List<String>();
this.multiselectList = new List<String>();
// 選択リスト値取得
Schema.DescribeFieldResult ratingFidldResult = Account.Rating.getDescribe();
List<Schema.PicklistEntry> ratingPicklistEntry = ratingFidldResult.getPicklistValues();
for (Schema.PicklistEntry pick : ratingPicklistEntry) {
this.selectList.add('Label = ' + String.valueOf(pick.getLabel()) + ' : ' + 'Value = ' + String.valueOf(pick.getValue()));
}
// 複数選択リスト値取得
Schema.DescribeFieldResult multiselectFidldResult = Account.Multiselect__c.getDescribe();
List<Schema.PicklistEntry> multiselectPicklistEntry = multiselectFidldResult.getPicklistValues();
for (Schema.PicklistEntry pick : multiselectPicklistEntry) {
this.multiselectList.add('Label = ' + String.valueOf(pick.getLabel()) + ' : ' + 'Value = ' + String.valueOf(pick.getValue()));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment