You need to sign in to do that
Don't have an account?

I want to get the selected row i:e the checked row from the page block table,my code is throwing error
public class testWrapper
{
public List<Wrapper> books{get; set;}
public integer count=0;
public boolean checked;
public testWrapper()
{
books = new List<Wrapper>();
for(Book__c b1 : [select name,Price__c from Book__c])
{
books.add(new Wrapper(b1));
}
}
public PageReference deleterow()
{
for(wrapper wp : books)
{
count=count+1;
if (wp.checked==true)
{
books.remove(count);
}
}
return null;
}
/*
public void selectedrows()
{
for(wrapper wp : books)
{
if (wp.checked==true)
{
}}
system.debug('no of rows selected'+count);
}
Public list<wrapper> getbooks()
{
books = new List<Wrapper>();
for(Book__c b1 : [select name,Price__c from Book__c])
{
books.add(new Wrapper(b1));
}
return books;
} */
public class Wrapper
{
public boolean checked {get; set;}
public Book__c bks {get; set;}
public Wrapper(Book__c bl)
{
this.bks = bl;
this.checked = false;
}
}
}
it is throwin this error
System.FinalException: Cannot modify a collection while it is being iterated.
Error is in expression '{!deleterow}' in component <apex:commandButton> in page testwrapper: Class.testWrapper.deleterow: line 20, column 1
Class.testWrapper.deleterow: line 20, column 1
{
public List<Wrapper> books{get; set;}
public integer count=0;
public boolean checked;
public testWrapper()
{
books = new List<Wrapper>();
for(Book__c b1 : [select name,Price__c from Book__c])
{
books.add(new Wrapper(b1));
}
}
public PageReference deleterow()
{
for(wrapper wp : books)
{
count=count+1;
if (wp.checked==true)
{
books.remove(count);
}
}
return null;
}
/*
public void selectedrows()
{
for(wrapper wp : books)
{
if (wp.checked==true)
{
}}
system.debug('no of rows selected'+count);
}
Public list<wrapper> getbooks()
{
books = new List<Wrapper>();
for(Book__c b1 : [select name,Price__c from Book__c])
{
books.add(new Wrapper(b1));
}
return books;
} */
public class Wrapper
{
public boolean checked {get; set;}
public Book__c bks {get; set;}
public Wrapper(Book__c bl)
{
this.bks = bl;
this.checked = false;
}
}
}
it is throwin this error
System.FinalException: Cannot modify a collection while it is being iterated.
Error is in expression '{!deleterow}' in component <apex:commandButton> in page testwrapper: Class.testWrapper.deleterow: line 20, column 1
Class.testWrapper.deleterow: line 20, column 1
Check the below link to delete the records.
http://www.mindfiresolutions.com/Delete-Bulk-Records-of-a-Custom-objectStandard-Object-1598.php
OR
Use the delete method in your controller from this link.
http://www.infallibletechie.com/2014/08/deleting-checked-rows-using-apex-in.html