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
Amita TatarAmita Tatar 

How to Pass selected Checkbox values from visualforce page to a TextArea Field in an Object.

Hi,

I have a requirement where i want to save the labels of selected checkboxes in a textarea field.
I am pasting my code below. Please help me for the same
My Class:

public class getLabel{

public List<sObjectWrapper> wrappers{get;set;}  
public List<String> AllLabels{get;set;}
public getLabel(ApexPages.StandardController controller) {
AllLabels = new List<String>();

String type = 'ProposalFields__c';
Map<String, Schema.SObjectType> m = Schema.getGlobalDescribe();
system.debug('Map is --------------->'+m);

Schema.SObjectType s= m.get(type);
system.debug('Type is--------->'+s);

Map<String, Schema.SObjectField> fieldMap = s.getDescribe().fields.getMap();
system.debug('FieldMap is------------->'+fieldMap);

for (String fieldName: fieldMap.keySet()) {
System.debug('Field API Name*********'+fieldName);       // list of all field API name
String label = fieldMap.get(fieldName).getDescribe().getLabel();   //It provides to get the object fields label.
system.debug('Label is----------------->'+label);
AllLabels.add(label);
}
}

public class sObjectWrapper{  
    public boolean isSelected{get;set;}  
    public ProposalFields__c prop{get;set;}  
    public sObjectWrapper(ProposalFields__c prop,Boolean isSelected){  
    this.prop= prop;  
    this.isSelected = isSelected;  
 }  
 }

}


VF Page

<apex:page showHeader="false" sidebar="false" standardController="Proposal_Form__c" extensions="getLabel">
<apex:form >
<style>
.panelWrapper .mainTitle {
   
    
}
</style>
<apex:outputPanel styleClass="panelWrapper" layout="block">
<apex:pageBlock title="Proposal Form">
<apex:pageBlockSection title="Service Requirements">
<apex:inputField value="{!Proposal_Form__c.Service_Family__c}"/>
<apex:inputfield value="{!Proposal_Form__c.Service_Type__c}"/>
<apex:inputField value="{!Proposal_Form__c.Sub_Service_Category__c}"/>
</apex:pageBlockSection>

<apex:pageBlockButtons location="Bottom">
<apex:commandButton value="Save" action="{!Save}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Available fields">
<apex:pageBlockTable var="lab" value="{!AllLabels}">
<apex:column headerValue="Labels">{!lab}</apex:column>

<apex:column >   
<apex:inputCheckbox />
</apex:column> 

</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:outputPanel>

</apex:form> 
</apex:page>

 
Lokesh KumarLokesh Kumar
HI Amita,

You can achieve this by the below Steps.

1. Get your Selected values in your custom controller and then add it to your object fields wherever you want to use. 

FYI.
https://salesforce.stackexchange.com/questions/104770/get-check-box-value-in-apex
https://salesforce.stackexchange.com/questions/104770/get-check-box-value-in-apex (https://salesforce.stackexchange.com/questions/49763/passing-the-check-box-value-to-the-apex-controller?rq=1)





 
Manish Mahajan 34Manish Mahajan 34
Hi,

To pass the multiple values of selected checkbox to controller, Wrapper class can be used. Follow this link for details and how to create Wrapper Class:
https://developer.salesforce.com/page/Wrapper_Class