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
anuj huriaanuj huria 

how to convert the picklist values to checkbox

Best Answer chosen by anuj huria
anuj huriaanuj huria
Thnks Onesh 
i want to do that with apex code, thnks for your concern

i have done it now here's the code for tht

controller code

public class abc1 {

    public Account account { get; set; }
    
    public abc1()
    {
    Id id=ApexPages.currentPage().getParameters().get('id');
    account=[SELECT Name,Industry FROM Account where Id= :id];
    
    
    
    
    }
    
    public List<selectOption> getIndustries()
    {
    
    List<SelectOption> options = new List<SelectOption>();
    Schema.DescribeFieldResult fieldresult=Schema.account.industry.getDescribe();
    List<Schema.PicklistEntry> ple=fieldResult.getPicklistValues();
    for(Schema.PicklistEntry f : ple)
   {
   
      options.add(new SelectOption(f.getLabel(), f.getValue()));
      
   } 
   return options;      
    }
    
   
    public PageReference save() 
    {
        try
         {
        upsert(account);
        } catch(System.DMLException e) 
        {
        ApexPages.addMessages(e);
        return null;
        }
        
     PageReference redirectSuccess = new ApexPages.StandardController(Account).view();
     return (redirectSuccess);
     }    
}

apex code

<apex:page controller="abc1">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:inputfield value="{!Account.name}" />
<apex:inputField value="{!Account.industry}"/>

</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="save" />





</apex:pageBlockButtons>
<apex:pageBlockSection >
<apex:selectCheckboxes id="industries" value="{!Account.industry}">
<apex:selectOptions value="{!industries}" />
</apex:selectCheckboxes>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

All Answers

Onesh ReddyOnesh Reddy
Hi Anuj,

Changing Field Data type is possible but there is a risk of loosing Data.
Check this for details.
https://help.salesforce.com/apex/HTViewHelpDoc?id=notes_on_changing_custom_field_types.htm&language=en

Please find the below process for changing field Data Type
1) Click  View Fields from the Quick Access.(Displays all Standard and Custom Fields)
2) Click Edit beside the Field name.
3) Click Change Data Type button present at the top.
4) Change the type and Save.

Regards, 
 
 
anuj huriaanuj huria
Thnks Onesh 
i want to do that with apex code, thnks for your concern

i have done it now here's the code for tht

controller code

public class abc1 {

    public Account account { get; set; }
    
    public abc1()
    {
    Id id=ApexPages.currentPage().getParameters().get('id');
    account=[SELECT Name,Industry FROM Account where Id= :id];
    
    
    
    
    }
    
    public List<selectOption> getIndustries()
    {
    
    List<SelectOption> options = new List<SelectOption>();
    Schema.DescribeFieldResult fieldresult=Schema.account.industry.getDescribe();
    List<Schema.PicklistEntry> ple=fieldResult.getPicklistValues();
    for(Schema.PicklistEntry f : ple)
   {
   
      options.add(new SelectOption(f.getLabel(), f.getValue()));
      
   } 
   return options;      
    }
    
   
    public PageReference save() 
    {
        try
         {
        upsert(account);
        } catch(System.DMLException e) 
        {
        ApexPages.addMessages(e);
        return null;
        }
        
     PageReference redirectSuccess = new ApexPages.StandardController(Account).view();
     return (redirectSuccess);
     }    
}

apex code

<apex:page controller="abc1">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:inputfield value="{!Account.name}" />
<apex:inputField value="{!Account.industry}"/>

</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="save" />





</apex:pageBlockButtons>
<apex:pageBlockSection >
<apex:selectCheckboxes id="industries" value="{!Account.industry}">
<apex:selectOptions value="{!industries}" />
</apex:selectCheckboxes>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
This was selected as the best answer