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
Sugandhi VermaSugandhi Verma 

Urgent Help!!! How to show selected checkbox item on another visualforce page.

Hi,
Please help me with the below scenario, I have Visualforce page through which I can select different checkbox value  and display the selected item on another visualforce  page without storing it in the object. My Requirment is when the multiple checkboxes are selected and Save botton is clicked, then the checked values need to be display on another page.
Selected Checkbox values should be store in Cookie.

Please help me on this scenario. ThankYou.
Below is my Visualforce Page.
<apex:page controller="TourHomeContrllr1" standardStylesheets="false" showHeader="false">
<apex:repeat value="{!naamClicked}" var="t">
    <div class="row">
    <div class="col-md-12 maincol" data-toggle="modal" data-target="#myModal" id="id1" >
                       
                     <div style="float:right;margin-top:5px;" class="img-responsive">
		<apex:outputField value="{!t.Tour_Place_Images__c}" style="width:200px;height:200px;" > </apex:outputField></div>
<br></br>                 
                <apex:form >    
                        <div style="float:right;"><apex:inputField value="{!t.Select__c}"></apex:inputField>
                        </div><br></br>   
                </apex:form>           
      </div> 
     </div>
     </apex:repeat>
 <apex:pageBlock >
                  <apex:form >
                  <apex:pageBlockSection >
                     <apex:commandButton action="{!addToCart}" value="Book Place" styleClass="btn btn-primary" rerender="select_places"/> </apex:pageBlockSection>
                         </apex:form>
                </apex:pageBlock>
                
                     <apex:pageBlock title="Your Places" id="select_places">
 <apex:outputText value="{!cartContents}" escape="true"/> </apex:pageBlock>
</apex:page>

 
Best Answer chosen by Sugandhi Verma
Mudasir WaniMudasir Wani
Hi Sugandhi,

Use the following code.
There may be some unused code which you can remove.

Page
<apex:page controller="wrapperAccountOpportunity" sidebar="false">
    <apex:form >
    <apex:commandButton value="Proceed with Selected" action="{!ProceedWithSelected}" reRender="panelId"/>
    <apex:pageBlock >
        <apex:outputPanel id="panelId">
            <apex:pageblockTable value="{!wrapperList}" var="wrapRec" rendered="{!normalList}">
               <apex:column value="{!wrapRec.acc.Name}" />
               <apex:column value="{!wrapRec.opp.Name}"/>
               <apex:column >
                   <apex:inputCheckbox value="{!wrapRec.selected}"/>
               </apex:column>
          </apex:pageblockTable>
          
           <apex:pageblockTable value="{!selectedWrapperList}" var="wrapRec" rendered="{!selectedList}">
               <apex:column value="{!wrapRec.acc.Name}" />
               <apex:column value="{!wrapRec.opp.Name}"/>
               <apex:column >
                   <apex:inputCheckbox value="{!wrapRec.selected}"/>
               </apex:column>
          </apex:pageblockTable>
        </apex:outputPanel>      
    </apex:pageBlock>
    </apex:form>
</apex:page>

Class
 
public class wrapperAccountOpportunity {
    
    public wrapperAccountOpportunity(){
        normalList = true;
        selectedList = false;
        fetchData();
    }
    public boolean normalList{get;set;}
    public boolean selectedList{get;set;}
    public void fetchData(){
       List<Opportunity> allOpps = [Select name,Id,AccountId from Opportunity ];
        //Parent Id set
        Set<id> parentIdSet = new Set<id>();
        //Create parent Id set 
        for(Opportunity OppertunityRec :allOpps){
        	parentIdSet.add(OppertunityRec.AccountId);
        }
        
        //Fetch all associated parents
        List<Account> allAssocaiatedAccounts = [Select name,id from Account where Id IN : parentIdSet];
        
        wrapperList = new list<myWrapperClass>();
        //For loop to set data
        for(Opportunity childRec : allOpps){
            //myWrapperClass wrapRec;
        	for(Account parentRec :allAssocaiatedAccounts){
        		if(parentRec.Id == childRec.AccountId){
        			myWrapperClass wrapRec = new myWrapperClass();
        			wrapRec.acc = parentRec;
        			wrapRec.opp = childRec;
        			wrapperList.add(wrapRec);
        		}
        	}
             
        	//Adding Opportunities without account
        	if(childRec.AccountId == null){
        	    	myWrapperClass wrapRec = new myWrapperClass();
        			//wrapRec.acc = null;
        			wrapRec.opp = childRec;
        			wrapperList.add(wrapRec);
        	}
         
        } 
    }
    public List<myWrapperClass> selectedWrapperList {get; set;}
    public void ProceedWithSelected(){
        selectedWrapperList = new List<myWrapperClass>();
        normalList = false;
        selectedList = true;
        for(myWrapperClass selectedWrapObj: wrapperList){
            system.debug('selectedWrapObj.selected  ---------'+selectedWrapObj.selected);
            if(selectedWrapObj.selected == true)
            selectedWrapperList.add(selectedWrapObj);
        }
        system.debug('selectedWrapperList size ---------'+selectedWrapperList.size());
    }
 
//Wrapper list 
public List<myWrapperClass> wrapperList {get; set;}
//Your wrapper 
public class myWrapperClass{
	public Account acc{get;set;}
	public Opportunity opp{get;set;}
	public Boolean selected {get; set;} 
	public myWrapperClass() { 
         selected = false; 
      } 
}
}

Mark it as solution if this solves your problem.
 

All Answers

Mudasir WaniMudasir Wani
Hi Sugandhi,

You can achieve using a wrapper class,
All you need to do is to create a new list of checked records and display it in the new page.

Here is one example where from you can take some code.
https://developer.salesforce.com/forums/ForumsMain?id=906F0000000B2zCIAS

Mark it as solution if this solves your problem.
Mudasir WaniMudasir Wani

Hi Sugandhi,

In the wrapper we are using selected checkbox.
Once you select the records in the first page you can make another list of those selected records by checking the value of selected and use the new list on your new page.
Mudasir WaniMudasir Wani
Hi Sugandhi,

Use the following code.
There may be some unused code which you can remove.

Page
<apex:page controller="wrapperAccountOpportunity" sidebar="false">
    <apex:form >
    <apex:commandButton value="Proceed with Selected" action="{!ProceedWithSelected}" reRender="panelId"/>
    <apex:pageBlock >
        <apex:outputPanel id="panelId">
            <apex:pageblockTable value="{!wrapperList}" var="wrapRec" rendered="{!normalList}">
               <apex:column value="{!wrapRec.acc.Name}" />
               <apex:column value="{!wrapRec.opp.Name}"/>
               <apex:column >
                   <apex:inputCheckbox value="{!wrapRec.selected}"/>
               </apex:column>
          </apex:pageblockTable>
          
           <apex:pageblockTable value="{!selectedWrapperList}" var="wrapRec" rendered="{!selectedList}">
               <apex:column value="{!wrapRec.acc.Name}" />
               <apex:column value="{!wrapRec.opp.Name}"/>
               <apex:column >
                   <apex:inputCheckbox value="{!wrapRec.selected}"/>
               </apex:column>
          </apex:pageblockTable>
        </apex:outputPanel>      
    </apex:pageBlock>
    </apex:form>
</apex:page>

Class
 
public class wrapperAccountOpportunity {
    
    public wrapperAccountOpportunity(){
        normalList = true;
        selectedList = false;
        fetchData();
    }
    public boolean normalList{get;set;}
    public boolean selectedList{get;set;}
    public void fetchData(){
       List<Opportunity> allOpps = [Select name,Id,AccountId from Opportunity ];
        //Parent Id set
        Set<id> parentIdSet = new Set<id>();
        //Create parent Id set 
        for(Opportunity OppertunityRec :allOpps){
        	parentIdSet.add(OppertunityRec.AccountId);
        }
        
        //Fetch all associated parents
        List<Account> allAssocaiatedAccounts = [Select name,id from Account where Id IN : parentIdSet];
        
        wrapperList = new list<myWrapperClass>();
        //For loop to set data
        for(Opportunity childRec : allOpps){
            //myWrapperClass wrapRec;
        	for(Account parentRec :allAssocaiatedAccounts){
        		if(parentRec.Id == childRec.AccountId){
        			myWrapperClass wrapRec = new myWrapperClass();
        			wrapRec.acc = parentRec;
        			wrapRec.opp = childRec;
        			wrapperList.add(wrapRec);
        		}
        	}
             
        	//Adding Opportunities without account
        	if(childRec.AccountId == null){
        	    	myWrapperClass wrapRec = new myWrapperClass();
        			//wrapRec.acc = null;
        			wrapRec.opp = childRec;
        			wrapperList.add(wrapRec);
        	}
         
        } 
    }
    public List<myWrapperClass> selectedWrapperList {get; set;}
    public void ProceedWithSelected(){
        selectedWrapperList = new List<myWrapperClass>();
        normalList = false;
        selectedList = true;
        for(myWrapperClass selectedWrapObj: wrapperList){
            system.debug('selectedWrapObj.selected  ---------'+selectedWrapObj.selected);
            if(selectedWrapObj.selected == true)
            selectedWrapperList.add(selectedWrapObj);
        }
        system.debug('selectedWrapperList size ---------'+selectedWrapperList.size());
    }
 
//Wrapper list 
public List<myWrapperClass> wrapperList {get; set;}
//Your wrapper 
public class myWrapperClass{
	public Account acc{get;set;}
	public Opportunity opp{get;set;}
	public Boolean selected {get; set;} 
	public myWrapperClass() { 
         selected = false; 
      } 
}
}

Mark it as solution if this solves your problem.
 
This was selected as the best answer
Mudasir WaniMudasir Wani
Hey Sugandhi,

Save the page and controller in your org.
go to the visualforce page and you can see all records with checkboxes.
There is a button on the top left of page just select some checkboxes and click on that button you can see only those selected contacts are displayed.

Let me know if you have any Question.

Please mark this as solution if this helps.
Mudasir WaniMudasir Wani

Sugandhi any update whether code works or not.

If it works please select the reply as best answer which solves your problem.
So that out efforts may not be wasted
Sugandhi VermaSugandhi Verma
Hii Mudasir,

Thanks for the answer. I am using wrapper in my code. I want to know how to show the selected list on another page.
Mudasir WaniMudasir Wani
Paste your wrapper code here and page sample code here


Also I want to know the requiremet is 

First you need to show all records in one page and after selecting some checkboxes you will show those records on another page right.
See my code of the below function
 
public void ProceedWithSelected(){
        selectedWrapperList = new List<myWrapperClass>();
        normalList = false;
        selectedList = true;
        for(myWrapperClass selectedWrapObj: wrapperList){
            system.debug('selectedWrapObj.selected  ---------'+selectedWrapObj.selected);
            if(selectedWrapObj.selected == true)
            selectedWrapperList.add(selectedWrapObj);
        }

Here I am seperating the records whose checkbox is selected in your case what i understood is that you will check 
Tour_Places__c.Select__c instead of selected.

 
Mudasir WaniMudasir Wani
Hello Please modify your class method as follows 
 
public List<Tour_Places__c> selectedWrapperList{ get; set;}
	public void ProceedWithSelected() {
	  selectedWrapperList = new List<Tour_Places__c>();
		normalList = false;
		selectedList = true;
		for(Tour_Places__c selectedWrapObj: tourInformation){
			system.debug('selectedWrapObj.selected  ---------'+selectedWrapObj.Select__c);
			if(selectedWrapObj.Select__c == true)
			selectedWrapperList.add(selectedWrapObj);
		}
		system.debug('selectedWrapperList size ---------'+selectedWrapperList.size()); 
	}

 
Mudasir WaniMudasir Wani
Create a new page and use the part of code you have.

My Second Page
<apex:page controller="wrapperAccountOpportunity" sidebar="false">
    <apex:form >
    <apex:pageBlock >
        <apex:outputPanel id="panelId">
            
           <apex:pageblockTable value="{!selectedWrapperList}" var="wrapRec" rendered="{!selectedList}">
               <apex:column value="{!wrapRec.acc.Name}" />
               <apex:column value="{!wrapRec.opp.Name}"/>
               <apex:column >
                   <apex:inputCheckbox value="{!wrapRec.selected}"/>
               </apex:column>
          </apex:pageblockTable>
        </apex:outputPanel>      
    </apex:pageBlock>
    </apex:form>
</apex:page>

And in the class use the following code just an updated function is used 

Update the class as 
public class wrapperAccountOpportunity {
    
    public wrapperAccountOpportunity(){
        normalList = true;
        selectedList = false;
        fetchData();
    }
    public boolean normalList{get;set;}
    public boolean selectedList{get;set;}
    public void fetchData(){
       List<Opportunity> allOpps = [Select name,Id,AccountId from Opportunity ];
        //Parent Id set
        Set<id> parentIdSet = new Set<id>();
        //Create parent Id set 
        for(Opportunity OppertunityRec :allOpps){
        	parentIdSet.add(OppertunityRec.AccountId);
        }
        
        //Fetch all associated parents
        List<Account> allAssocaiatedAccounts = [Select name,id from Account where Id IN : parentIdSet];
        
        wrapperList = new list<myWrapperClass>();
        //For loop to set data
        for(Opportunity childRec : allOpps){
            //myWrapperClass wrapRec;
        	for(Account parentRec :allAssocaiatedAccounts){
        		if(parentRec.Id == childRec.AccountId){
        			myWrapperClass wrapRec = new myWrapperClass();
        			wrapRec.acc = parentRec;
        			wrapRec.opp = childRec;
        			wrapperList.add(wrapRec);
        		}
        	}
             
        	//Adding Opportunities without account
        	if(childRec.AccountId == null){
        	    	myWrapperClass wrapRec = new myWrapperClass();
        			//wrapRec.acc = null;
        			wrapRec.opp = childRec;
        			wrapperList.add(wrapRec);
        	}
         
        } 
    }
    public List<myWrapperClass> selectedWrapperList {get; set;}
    public PageReference ProceedWithSelected(){
        selectedWrapperList = new List<myWrapperClass>();
        normalList = false;
        selectedList = true;
        for(myWrapperClass selectedWrapObj: wrapperList){
            system.debug('selectedWrapObj.selected  ---------'+selectedWrapObj.selected);
            if(selectedWrapObj.selected == true)
            selectedWrapperList.add(selectedWrapObj);
        }
        system.debug('selectedWrapperList size ---------'+selectedWrapperList.size());
        return null;
    }
     public PageReference ProceedWithSelectedToNextPage(){
        selectedWrapperList = new List<myWrapperClass>();
        normalList = false;
        selectedList = true;
        for(myWrapperClass selectedWrapObj: wrapperList){
            system.debug('selectedWrapObj.selected  ---------'+selectedWrapObj.selected);
            if(selectedWrapObj.selected == true)
            selectedWrapperList.add(selectedWrapObj);
        }
        system.debug('selectedWrapperList size ---------'+selectedWrapperList.size());
        PageReference pageRef = new PageReference('/apex/AccountOpportunityTwoPage');
        pageRef.setRedirect(false);
        return pageRef;
    }
 
//Wrapper list 
public List<myWrapperClass> wrapperList {get; set;}
//Your wrapper 
public class myWrapperClass{
	public Account acc{get;set;}
	public Opportunity opp{get;set;}
	public Boolean selected {get; set;} 
	public myWrapperClass() { 
         selected = false; 
      } 
}
}
I have created a new action and added the new page URL  and 
pageRef.setRedirect(false);
 
public PageReference ProceedWithSelectedToNextPage(){
        selectedWrapperList = new List<myWrapperClass>();
        normalList = false;
        selectedList = true;
        for(myWrapperClass selectedWrapObj: wrapperList){
            system.debug('selectedWrapObj.selected  ---------'+selectedWrapObj.selected);
            if(selectedWrapObj.selected == true)
            selectedWrapperList.add(selectedWrapObj);
        }
        system.debug('selectedWrapperList size ---------'+selectedWrapperList.size());
        PageReference pageRef = new PageReference('/apex/AccountOpportunityTwoPage');
        pageRef.setRedirect(false);
        return pageRef;
    }
My First Page
<apex:page controller="wrapperAccountOpportunity" sidebar="false">
    <apex:form >
    <apex:commandButton value="Proceed with Selected" action="{!ProceedWithSelected}" reRender="panelId"/>
    <apex:commandButton value="Proceed with Selected to Next Page" action="{!ProceedWithSelectedToNextPage}" />
    <apex:pageBlock >
        <apex:outputPanel id="panelId">
            <apex:pageblockTable value="{!wrapperList}" var="wrapRec" rendered="{!normalList}">
               <apex:column value="{!wrapRec.acc.Name}" />
               <apex:column value="{!wrapRec.opp.Name}"/>
               <apex:column >
                   <apex:inputCheckbox value="{!wrapRec.selected}"/>
               </apex:column>
          </apex:pageblockTable>
          
           <apex:pageblockTable value="{!selectedWrapperList}" var="wrapRec" rendered="{!selectedList}">
               <apex:column value="{!wrapRec.acc.Name}" />
               <apex:column value="{!wrapRec.opp.Name}"/>
               <apex:column >
                   <apex:inputCheckbox value="{!wrapRec.selected}"/>
               </apex:column>
          </apex:pageblockTable>
        </apex:outputPanel>      
    </apex:pageBlock>
    </apex:form>
</apex:page>


Mark it as solution if this solves your problem.
 
Sugandhi VermaSugandhi Verma
Hii Mudasir,

The Problem is solved. I was doing it with cookies but learnt the use of wrapper also.Thanks alot for your valuable time and helping me.

Thanks and Regards,
Sugandhi