+ Start a Discussion
smith indiasmith india 

swap 2 records when check boxes are checked don't select more than 2

Error: Conversion Error setting value '' for '#{w.check}'.

 

<apex:page controller="swapcls" >
<apex:form >
<apex:pageblock >
<apex:pageblockTable value="{!wrap}" var="w">
<apex:column >
<apex:selectCheckboxes value="{!w.check}"/>
</apex:column>
<apex:column value="{!w.name.name}"/>
</apex:pageblockTable>
<apex:commandButton value="swap" action="{!swaprec}" />
<apex:pageMessage summary="Select any Two Records" severity="warning" strength="3" rendered="{!pgmsg}" />
<apex:pageMessages />
</apex:pageblock>
</apex:form>
</apex:page>

 

 

class

 

public with sharing class swapcls  {

public boolean pgmsg { get; set; }

public PageReference swaprec()  {
list<swap_record__c> lstswap = new list<swap_record__c>();
 for(wrapper s:wrap)
{
if(s.check == true)
lstswap.add(s.name);
}
System.debug('------------------>'+lstswap);
 if(lstswap.size()>2 || lstswap.size()==1)
{
pgmsg = true;
}
else
{
swap_record__c a;
a = lstswap[0];
lstswap[0] = lstswap[1];
lstswap[1] = a;
}

agereference ref = new pagereference('/apex/swaprecords');
return ref;
}

public list<wrapper> wrap { get; set; }

public class wrapper
{
public boolean check{get; set;}
public swap_record__c name{get; set;}
public integer num{get;set;}
public wrapper(boolean b, swap_record__c n, integer nbr)
{
check = b;
name = n;
num = nbr;
}
}
public swapcls()
{
wrap = new list<wrapper>();
list<swap_record__c> lst = [select name from swap_record__c];
integer i=0;
for(swap_record__C c:lst)
{
wrap.add(new wrapper(false,c,i));
i++;
}}}

 

 
 


 



krishkrishnakrishkrishna
this is not working please send me clear code
krishkrishnakrishkrishna
I am selecting two checkboxes swaping the two records