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
Karanbir SinghKaranbir Singh 

Delete button not deleting records from list

I have created 2 block in my VF page. one for taking input and the other for displaying list of accounts.

I want edit and delete functionality for each Account record in the list.

I've successfully created everything except the delete functionality of the delete button. The controller and Markup code are below:


public class AccountCustom {
  public List<account> accountlist = new List<account>();
    public Account account{get; set;}
    ApexPages.StandardSetController ssc;
   public List<account> accdelete = new List<account>();
    public String accid{get; set;}
        public AccountCustom()
        //Method with the querry for the list
        public void accountQuerry()
            accountlist = [SELECT Id, Name, Phone FROM Account];
            ApexPages.StandardSetController ssc = new ApexPages.StandardSetController(accountlist);
        //get Method being called from VF page to display list
        public List<account> getAccountList()
            return accountlist;
        //Save Method
        public void save()
            account = new Account();
            insert account;

        //Method for deleting accounts from the list
        public void deleteAccount()
            accdelete = [SELECT Id, Name, Phone FROM Account WHERE Id = :accid];
            if(accdelete.size() > 0)
               if(accdelete[0].Id != '')
                delete accdelete;

VF Page:

<apex:page controller="AccountCustom">
    <apex:form >
        <apex:pageBlock title="Create/Update Account">                                
            <apex:pageBlockSection > 
                <apex:inputField value="{!account.Name}"/>                                
                <apex:inputField value="{!account.Phone}"/>                            
            <apex:commandButton action="{!save}" value="Save" />                    

        <apex:pageBlock title="List Of Accounts">                                    
            <apex:pageBlockTable value="{!AccountList}" var="ac">                    
                <apex:column width="40">
                    <apex:outputLink value="/{!}/e?retURL=%2F{!}">
                <apex:column value="{!ac.Name}"/>
                <apex:column value="{!ac.Phone}"/>
                <apex:column value="{!}"/>
                <apex:column >
                    <apex:commandButton action="{!deleteAccount}" value="Delete" immediate="true">            
                        <apex:param value="{!}" assignTo="{!accid}"/>

Subhash GarhwalSubhash Garhwal
Hi Karanbir,

Please reomve immediate="true" from command button and try.
Karanbir SinghKaranbir Singh
Hi Subhash,

Thank you for the answer,
but i have done that purposely to bypass the data validations on the page.  
Subhash GarhwalSubhash Garhwal
Than use <apex:param to pass values from page to controller.