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
rajaraja 

How to display picklsit value as checkbox in visualforce?

Hello All,

I have a requirement like , i want to display3 checkboxes in VF and then  if suppose 2 checkboxes are checked , i need to dsplay Corrected values :Scope,Budget.  How can i perform this requirement ?

User-added image

I tried like below :
i created one of the picklist with three values . displayed those 3 values as checkboxes in VF. but after saving this record the values are not showing in the related list. and one more is ,if user tried to edit record it is showing picklist. not checkbox . please find attached screenshot for reference
NagendraNagendra (Salesforce Developers) 
Hi Raja,

Please find sample code below for your reference,and modify it as per your requirement which helps you to accelerate with the above requirement.

Apex Class:
public String STEP1_INTERACTION {get {return 'Interaction';}}


    


    public String step {get; set;}

   

    public Interaction__c InteractionRequest {get; set;}

 
    private String retUrl;

 
    public InteractionController() {
        step = STEP1_INTERACTION;

   
        ID accountId = ApexPages.currentPage().getParameters().get('accountId');


        
            InteractionRequest = new Interaction__c(Account__c =accountId);

            if (accountId != null)
                retUrl = '/' + accountId;
       }
    
    
    public List <SelectOption>
              generateMPOptions(List <Schema.PicklistEntry> ple) {
               List <SelectOption> options = new List <SelectOption> ();
            for( Schema.PicklistEntry f : ple) {
              options.add(new SelectOption(f.getValue(), f.getLabel()));
            } return options;
            }

    public String[] MPItems { get {
          String[] selected = new List <String>();
          List <SelectOption> sos = this.MPOptions;
              for(SelectOption s : sos) {
                    if (this.InteractionRequest.Discussion_Points__c.contains(s.getValue()))
              selected.add(s.getValue());
}
return selected;
} 

public set {
  String selectedConcat = '';
  for(String s : value) {
    if (selectedConcat == '') selectedConcat += s;
  else selectedConcat += ';' + s;
} 

        this.InteractionRequest.Discussion_Points__c = selectedConcat;
            upsert this.InteractionRequest;
            }}

 
public List <SelectOption> MPOptions {get {
  return this.generateMPOptions(Interaction__c.Discussion_Points__c.getDescribe().getPicklistValues());
} private set;}
Visual Force Page:
<apex:pageBlockSectionItem > 
      <apex:outputtext     value="InteractionRequest.Discussion_Points__c"/>
<apex:selectCheckboxes value="{!MPItems}" layout="pageDirection">
<apex:selectOptions value="{!MPOptions}"/>
</apex:selectCheckboxes>
</apex:pageBlockSectionItem>
Kindly mark this post as solved if the information help's so that it gets removed from the unanswered queue and becomes a proper solution which results in helping others who are really in need of it.

Best Regards,
Nagendra.P