-1

Any help I have a delete button in VF but it won't work.

this is my controller

public class AddmultipleAccountsController {

    Account account = new Account();
    public list<Account> showList = new list<Account>([select Id, Name, Type, Industry, AccountNumber from Account where type='Prospect']);
       public list<Account> listAccount{get; set;}

    public AddmultipleAccountsController(){
            listAccount=new list<Account>();
            listAccount.add(account);
        }

    Public void addAccount(){
            Account acc = new Account();
            listAccount.add(acc);
        }
    public PageReference saveAccount() {
            for(Integer i=0; i<listAccount.size(); i++){
                    insert listAccount;
                }
            return null;
        }

   public list<Account> getshowList(){
        return showList;
    }
}

here my VF

 </apex:pageBlock>
    <h2 style="font-size: 1rem;" >Account List</h2>
     <apex:pageBlock>
            <apex:pageBlockTable value="{!showList}" id="accountId" var="a">
                <apex:column headerValue="Account Name" value="{!a.Name}"/>
                <apex:column headerValue="Account Number" value="{!a.AccountNumber}"/>
                <apex:column headerValue="Account Type" value="{!a.Type}"/>
                <apex:column headervalue="Account Industry" value="{!a.Industry}"/>
                <apex:column headervalue="Action">
                <apex:commandButton value="Delete"/>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
2
  • logically your complete class is wrong. for deleting purpose you have no any method. and you are performing dml(insert) operation in for loop and you are adding values in list in constructor part. – cloudZigZag Sep 10 '18 at 11:31
  • what i should you advice? and what i am suppose to do first – zane Sep 12 '18 at 5:11
0

There is no action attribute specified in the command button. The value attribute will only show the button's text as Delete. You need to associate the action attribute for deletion on command button.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.