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
Alexander AtkinsonAlexander Atkinson 

Visual Force Page Select all checkboxes and pass all values into Apex

Hi I have a visual force page that shows a table of information. One of the columns is a checkbox. You can check and uncheck these individually and their values are successfully sent or removed from apex. Whatever is checked is sent to a new page to be shown as a quote.

I'm trying to implement a "check all boxes" main checkbox at the top of my page and pass all the data in.

Visual Force:
<table width="100%" class="data-table">
                <tr class="headerRow">
                    <th style="font-size: 14px; font-weight: bold; text-align: center" width="4%">Select <!--Checkall box underneath this--></th>
                </tr>
                <tr height="2px"></tr>
                <apex:repeat value="{!data}" var="Results">
                    <tr>
                        <td style="text-align: center" width="4%"><input type="checkbox" value="{!Results.Id}" onChange="quotesCheck('{!Results.id}', this.checked);" /></td>
					</tr>
                    <tr height="2px">
                    </tr>
                </apex:repeat>
			</table>
						
			<apex:actionFunction action="{!addQuotesToChecked}" name="quotesCheck" reRender="sasa">
                <apex:param name="quoteId" value=""/> 
                <apex:param name="chkValue" value=""/>
        	</apex:actionFunction>

Apex function being called:
public PageReference addQuotesToChecked()
    {
        string quoteId = Apexpages.currentPage().getParameters().get('quoteId');
        string chkValue = Apexpages.currentPage().getParameters().get('chkValue');
        System.debug('quoteId '+quoteId);
        System.debug('chkValue '+chkValue);
        if(checkedQuotes ==null)
        {
            system.debug('null again');
            checkedQuotes= new List<id>();
            checkedQuotes.add(quoteId);
        }
        else
        {
            if(chkValue=='true')
            {
                checkedQuotes.add(quoteId);
            }
            else
            {
               integer i= checkedQuotes.indexOf(quoteId);
                checkedQuotes.remove(i);
            }
             
        }
        integer i=checkedQuotes.size();
        system.debug(i);
       
        return null;
    }

 
Deepali KulshresthaDeepali Kulshrestha
Hi Alexander,

I went through the query of yours regarding the selection of all checkboxes and passing the values to the apex and found some links that may be helpful, in those they have used the wrapper class in order to contain the values of the checkboxes. Please refer to the following links as they may be helpful in solving your query.

http://www.sfdcpoint.com/salesforce/select-all-checkbox-using-javascript-in-visualforce-page/
https://www.biswajeetsamal.com/blog/select-all-checkbox-using-javascript-in-visualforce-page/

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha