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
geetha b 8geetha b 8 

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
Anoop yadavAnoop yadav
Hi,

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.