+ Start a Discussion
ManidManid 

implemented this delete the records from data base but not from the list.

wrapper class:
public class AccountWrapper {
    public account acc {get;set;}
    public boolean flag  {get;set;}       
}
class:
public class Dmlexamle6 {
    public string allrec                 {get;set;}
    public list<AccountWrapper> aws      {get;set;}
    
    public void searched(){
        aws=new list<AccountWrapper>();
        list<account> accs=[select name,phone,industry from account];
        for(account a:accs){
            AccountWrapper aw=new AccountWrapper();
            aw.acc=a;
            aw.flag=false;
            aws.add(aw);
        }
    }
    public void delects(){
        list<account> a= new list<account>();
        list<AccountWrapper> aes=new list<AccountWrapper>();
        for(AccountWrapper aw:aws){
               if(aw.flag==true){
               a.add(aw.acc);
               }
        }
        delete a;
    }
}
vf page:
<apex:page controller="Dmlexamle6">
    <apex:form >
        <apex:inputText value="{!allrec}"/>
        <apex:commandButton value="search" action="{!searched}"/>
        <apex:pageblock rendered="{! !isnull(aws)}">
            <apex:pageBlockButtons location="top">
                <apex:commandbutton value="delete" action="{!delects}"/>
            </apex:pageBlockButtons>
            <apex:pageblocktable value="{!aws}" var="b">
                <apex:column >
                    <apex:facet name="header"><apex:inputcheckbox /></apex:facet>
                    <apex:inputCheckbox value="{!b.flag}"/>
                </apex:column>
                <apex:column value="{!b.acc.name}"/>
                <apex:column value="{!b.acc.phone}"/>
                <apex:column value="{!b.acc.industry}"/>
            </apex:pageblocktable>
        </apex:pageblock>
    </apex:form>
</apex:page>

it gives  all records but after press delete button from database it delets but in list it not delets.User-added image
Vinod AdminVinod Admin
Hi Manid,

You need to find the below code why it is deleting backend and not showing in list is? You are using seperate method to load all these records so you can use below code.

<apex:page controller="Dmlexamle6">
    <apex:form >
        <apex:inputText value="{!allrec}"/>
        <apex:commandButton value="search" action="{!searched}"/>
        <apex:pageblock rendered="{! !isnull(aws)}">
            <apex:pageBlockButtons location="top">
                <apex:commandbutton value="delete" action="{!delects}"/>
            </apex:pageBlockButtons>
            <apex:pageblocktable value="{!aws}" var="b">
                <apex:column >
                    <apex:facet name="header"><apex:inputcheckbox /></apex:facet>
                    <apex:inputCheckbox value="{!b.flag}"/>
                </apex:column>
                <apex:column value="{!b.acc.name}"/>
                <apex:column value="{!b.acc.phone}"/>
                <apex:column value="{!b.acc.industry}"/>
            </apex:pageblocktable>
        </apex:pageblock>
    </apex:form>
</apex:page>

Class
public class Dmlexamle6 {
    public string allrec                 {get;set;}
    public list<AccountWrapper> aws      {get;set;}
    
    public void searched(){
        aws=new list<AccountWrapper>();
        list<account> accs=[select name,phone,industry from account];
        for(account a:accs){
            AccountWrapper aw=new AccountWrapper();
            aw.acc=a;
            aw.flag=false;
            aws.add(aw);
        }
    }
    public void delects(){
        list<account> a= new list<account>();
        list<AccountWrapper> aes=new list<AccountWrapper>();
        for(AccountWrapper aw:aws){
               if(aw.flag==true){
               a.add(aw.acc);
               }
        }
        delete a;
        searched();
    }
}: