+ Start a Discussion

How to populate the values in multiselect picklist dynamically

I have an object rules which has records with one of the fields(rule Name) as  rule 1 , rule 2 , rule 3 etc......

Now on some other page or object I want to have a picklist which fetches values from rule object i.e. rule name.

I essence the value of picklist should be rule 1 , rule 2, rule 3 etc..........


How can we achieve this?


Try this...



List<SelectOption> getRules() {
	List<SelectOption> rules = new List<SelectOption>();
	for ( Rule__c rule : [select Id, Name from Rule__c] ) {
		rules.add(new SelectOption(rule.Id, rule.Name));
	return rules;



<apex:selectList multiselect="true" size="3">
	<apex:selectOptions value="{!rules}"/>