• geetha b 8
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 3
    Replies
<apex:page standardController="Account" extensions="contrller">
  <apex:form >
    <apex:pageblock >
       <!-- Display Account related Contacts -->
       <apex:pageBlockTable value="{!relatedContacts}" var="val">
         <apex:column value="{!val.name}"/>
         <apex:column value="{!val.email}"/>
       </apex:pageBlockTable>
    </apex:pageblock>
  </apex:form>
</apex:page>


_________controller_______________

public with sharing class contrller {
Public id Current_Acc_Id;

    public contrller(ApexPages.StandardController controller) {
    Current_Acc_Id = controller.getRecord().id;
    system.debug('--------------------Current_Acc_Id------------------------'+Current_Acc_Id );
    }

    public List<Contact> getrelatedContacts(){
        List <contact> conList = New List<Contact>();
        system.debug('--------------------Current_Acc_Id------------------------'+Current_Acc_Id );
        for(Account acc:[select id,name,(select name,id,email from contacts) from account where id=:Current_Acc_Id])
        {
       
           for(contact con:acc.contacts)
               conList.add(con);
        }
        return conList;
    }
no records are displayed
 
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
Here is mu code

<apex:page controller="testWrapper">
  <!-- Using wrapper class -->
 <apex:form>
   <apex:pageBlockSection>
     <apex:pageBlockTable value="{!books}" var="b">
         <apex:column width = "25px">
                <apex:inputCheckbox value="{!b.checked}" />
            </apex:column>
         <apex:column value="{!b.b1.Name}"/>
        
         <apex:column value="{!b.b1.Price__c}"/>
     </apex:pageBlockTable>
   </apex:pageBlockSection> 
 </apex:form>
 </apex:page>
---------------------------------------------------class--------------------------------------------------
public class testWrapper
{
  public List<Wrapper> books{get; set;}
  public testWrapper()
  {
 
     books = new List<Wrapper>();
     for(Book__c b1 : [select name,Price__c from Book__c])
     {

         books.add(new wrapper(b1));
        
      }
   }  
   public class Wrapper
   {
        public boolean checked {get; set;}
        public Book__c bl {get; set;}
        public Wrapper(Book__c bl)
        {
            this.bl = bl;
            this.checked = false;
        }
    }
 

}
Here is mu code

<apex:page controller="testWrapper">
  <!-- Using wrapper class -->
 <apex:form>
   <apex:pageBlockSection>
     <apex:pageBlockTable value="{!books}" var="b">
         <apex:column width = "25px">
                <apex:inputCheckbox value="{!b.checked}" />
            </apex:column>
         <apex:column value="{!b.b1.Name}"/>
        
         <apex:column value="{!b.b1.Price__c}"/>
     </apex:pageBlockTable>
   </apex:pageBlockSection> 
 </apex:form>
 </apex:page>
---------------------------------------------------class--------------------------------------------------
public class testWrapper
{
  public List<Wrapper> books{get; set;}
  public testWrapper()
  {
 
     books = new List<Wrapper>();
     for(Book__c b1 : [select name,Price__c from Book__c])
     {

         books.add(new wrapper(b1));
        
      }
   }  
   public class Wrapper
   {
        public boolean checked {get; set;}
        public Book__c bl {get; set;}
        public Wrapper(Book__c bl)
        {
            this.bl = bl;
            this.checked = false;
        }
    }
 

}