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
MissaTXREGNMissaTXREGN 

Convert Picklist to Checkboxes

Okay, this is probably simple but for the life of me, I can't figure out how to do this.

 

I need to a picklist to display as checkboxes in my visualforce page.  I need the box that is checked to save to the picklist value field.  Does anyone have any sample code.  

 

Thanks in advance. 

Starz26Starz26

Not an easy task to do.

 

You would have to create all the variable for the various values of the checkboxes, display them on the VF page. Then us the controller or extension to take the value of the checkbox and update the picklist filed which would not be shown anywhere on the page.

 

To my knowledge you cannot change the field type on the page from picklist to checkbox.

MissaTXREGNMissaTXREGN

This is the code I found and modified for the controller and page.  However I'm throwing a de reference a null object error.  Can you see what I'm missing.  

 

    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 section

 

 <apex:pageBlockSectionItem > 
      <apex:outputtext     value="InteractionRequest.Discussion_Points__c"/>
<apex:selectCheckboxes value="{!MPItems}" layout="pageDirection">
<apex:selectOptions value="{!MPOptions}"/>
</apex:selectCheckboxes>
</apex:pageBlockSectionItem>

 

pwsadpwsad

Is ur task done?

I need to implement the same thing.plz help me out.