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
Merry SMerry S 

pass checkbox value from one vf page to another vf page

I have a visualforce page that is used as a checklist for an opportunity. The check boxes are not related to any fields. When the form is submitted the info is passed to another vf page that is use to email and render a pdf. I cannot get the boolean value to pass to the second page.

This is the variable in my controller (same controller for both pages)
public boolean checkbox1 {get;set;}

This is what I have for the field on the initial page:
<div class="slds-checkbox">
                                          <input type="checkbox" name="options" id="checkbox-1" value="{!checkbox1}" />
                                          <label class="slds-checkbox__label" for="checkbox-1">
                                            <span class="slds-checkbox_faux"></span>
                                            <span class="slds-form-element__label">Updated the Salesforce opportunity to include pertinent information including win data?</span>
And this is on the 2nd page:
<apex:outputText >Updated the Salesforce opportunity to include pertinent information including win data? - {!checkbox1}</apex:outputText>
And this is the pageref:
PageReference pdf =  Page.Order_Submission_chklst_PDF;
        pdf.getParameters().put('id', oppid);
          // Take the PDF content
        Blob b = pdf.getContentAsPDF();
        // Create the email attachment
        Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
        efa.setContentType('application/pdf');
        efa.setFileName('attachment.pdf');
        efa.setInline(false);
        efa.setBody(b);
        
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        String[] toAddresses = new String[] {email};
        mail.setToAddresses(toAddresses);
        mail.setSubject('Order Submission'); 
        
        mail.plainTextBody = 'Updated the Salesforce opportunity to include pertinent information including win data? : '+checkbox1;
        
        mail.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});
        Messaging.SendEmail(new Messaging.SingleEmailMessage[] {mail});
            return null;
How do I pass the T/F to the other page?
I have looked at a few posts, but more are related to showing how to do it with a checkbox field and not just stand alone checkbox.


 
Deepali KulshresthaDeepali Kulshrestha
Hi Merry,

You can take the value received from the checkbox to another variable in the controller and pass that value to the next page. Here is an example of doing so:
VF page 1 –

      <apex:page docType=”html-5.0″ controller=”mycontroller” >
        <apex:form >
            <apex:pageBlock >
                <apex:pageBlockSection>
                    Date1: <apex:input type=”date” value=”{!date1}”/>
                    Date2: <apex:input type=”date” value=”{!date2}”/>
                </apex:pageBlockSection>
            </apex:pageBlock>
            <apex:commandButton value=”Display” action=”{!display}” />
        </apex:form>
    </apex:page>

VF page 2 –

    <apex:page docType=”html-5.0″ controller=”mycontroller” >
        <apex:form >
            <apex:pageBlock >
                <apex:pageBlockSection>
                    Date3: <apex:input type=”date” value=”{!date3}”/>
                    Date4: <apex:input type=”date” value=”{!date4}”/>
                </apex:pageBlockSection>
            </apex:pageBlock>
        </apex:form>
    </apex:page>

Controller –

    public class mycontroller {

        public date date1 {set;get;}
        public date date2 {set;get;}
        public date date3 {set;get;}
        public date date4 {set;get;}

            public pagereference display()
              {
                date3 = date1;
                date4 = date2;

                pagereference pr = new pagereference(‘/apex/page2’);
                return pr;
               }

    }

Please refer to the following links as they may be helpful:
https://salesforce.stackexchange.com/questions/87704/passing-visualforce-value-to-another-visualforce
https://salesforce.stackexchange.com/questions/109021/how-to-move-selected-check-box-rows-from-one-vf-to-another

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