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
Sonam PatilSonam Patil 

Error: Wrapper Class

Hi,
Below is the code of wrapper class of to display the Contacts of selected Accounts and also delete the selected Accounts.
It is displayind the contacts but Account is not getting deleted.
Can anyone help me to solve this problem?

<apex:page controller="charantest">
    <apex:form >
    <apex:pageBlock >
        <apex:pageBlockButtons location="top">
            <apex:commandButton value="Select" action="{!selected}"  />
            <apex:commandButton value="Delete" action="{!del}" reRender="pg"/>
        </apex:pageBlockButtons>
            <apex:pageBlockTable value="{!ch}" var="ct">
                <apex:column headerValue="Select" >
                    <apex:inputCheckbox value="{!ct.isSelected}" />
                </apex:column>
                    <apex:column value="{!ct.act.Name}"/>
                    <apex:column value="{!ct.act.Industry}"/>
            </apex:pageBlockTable>
            
            <apex:pageBlockTable value="{!con}" var="c" id="pg">
                <apex:column value="{!c.lastName}"/>
            </apex:pageBlockTable>
    </apex:pageBlock>
    </apex:form>

</apex:page>

public class charantest {

   
    public List<charnwrap> ch{get;set;}
    public List<ID> acc;
    public List<Contact> con{get;set;}
    
    public Charantest(){
        ch= new List<Charnwrap>();
        for(Account c:[Select id,name,industry from Account limit 5 offset 10]){
        ch.add(new charnwrap(c));
            
        }
        }
        
        public void selected(){
        acc= new List<Id>();
        for(charnwrap cw: ch){
        if(cw.isSelected==true){
        acc.add(cw.act.Id); 
        }
        }
    con=new List<contact>();
    con=[Select Id, lastName from Contact where AccountId=:acc];
    }

 public PageReference del() {
    for(charnwrap wp:ch){
    if(wp.isSelected==true){
    Delete wp.act;
    }
    }
        return null;
    }

    
    
    public class charnwrap{
        public Account act{get;set;}
        public boolean isSelected{get; set;}
        public charnwrap(Account a){
            this.act=a;
            isSelected=false;
        }
    }

}