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
Dilip KulkarniDilip Kulkarni 

VF page for accounts list

Hi Experts,
I want to create a account list VF page where it will have two links Edit and Del, when clicked on Edit,account record should be editable and when you click on Del,it should show dialog box,when you confirm it, it should delete record and if you cancel it should not delete record.

Kindly provide me the code for the same.

Regards
Ankur Saini 9Ankur Saini 9
Hi Dilip

try this one:

page:
<apex:page standardController="Opportunity" extensions="AccList"> 
    
  <apex:form id="frm">
  
  <apex:outputPanel id="theValues"/>

    <apex:pageBlock title="Accounts" id="pg">
    
        <apex:pageBlockTable var="acclst" value="{!accDataList}" id="table">
            
            <apex:column headerValue="Action" id="all">
                <apex:outputLink value="/{!acclst.id}/e" target="_parent">Edit
                </apex:outputLink>
                &nbsp;|&nbsp;
                <apex:commandLink onclick="if(confirm('Are you sure ?'))deleteAccount('{!acclst.id}');" value="Del" reRender="table">                   
                </apex:commandLink>
            </apex:column>           
            
            <apex:column headerValue="Name">
                <apex:outputLink value="/{!acclst.id}" target="_parent" title="{!acclst.name}">{!acclst.name}
                </apex:outputLink>
            </apex:column>                
               
        </apex:pageBlockTable>
        
        <apex:actionFunction action="{!deleteAccount}" name="deleteAccount" reRender="table">
           <apex:param name="acco" value="" assignTo="{!id}"/>
        </apex:actionFunction>
    </apex:pageBlock>
   </apex:form>
</apex:page>

class:
public with sharing class AccList {
    public List<Account> accDataList{get; set;}
    public string id{get;set;}
       
    //********************CONTROLLER*************************
    public AccList(ApexPages.StandardController controller) {
        // accDataList = new List<Account>();               
         accDataList= [SELECT id,name FROM Account];
         
    }
    
    //************EDIT LINK******************
    public PageReference myEdit(){
    String aid=apexpages.currentpage().getparameters().get('aid');
         PageReference redirecturl = new PageReference('/'+aid+'/e?retURL=%2F'+aId);
         redirecturl.setRedirect(true);        
         return redirecturl;
    }
    
    //*****************DEL LINK********************    
    public PageReference deleteAccount(){
        if(id!=null){
            Account  a = [select id from account where id=:id limit 1];       
        if(a!=null){
            delete a;
        }
        }  
       PageReference redirecturl = new PageReference('/apex/TaskList2');
         redirecturl.setRedirect(true);        
         return redirecturl; 
    }
}

Thanks
Ankur Saini

http://mirketa.com
Akshay_DhimanAkshay_Dhiman
Hi Dilip,
The following code helps you as want to do. In following Visualforce page there are two link edit and delete which is  edit and delete only a particular account record.
The code is here -
Visualforce Page:
<apex:page standardController="Account" extensions="AccountListController" >
<apex:form id="form">
<apex:pageBlock title="Acconut List" id="account_list">
<apex:pageBlockTable value="{!accList}" var="account">
<apex:column headerValue="Action">
<apex:commandLink value="Edit" reRender="account_list" rendered="{!account.id!=editList}">
<apex:param assignTo="{!editList}" name="Edit"
value="{!account.id}" />
</apex:commandLink>
<apex:commandLink value="Save" reRender="account_list" rendered="{!account.id==editList}" action="{!saveRecord}" />&nbsp;
<a href="javascript:if (window.confirm('Are you sure?')) deleteAccount('{!account.Id}');">Del</a>
</apex:column>
<apex:column>
<apex:facet name="header">Name</apex:facet>
<apex:outputField value="{!account.Name}" rendered="{!account.id!=editList}" />
<apex:inputField value="{!account.Name}" rendered="{!account.id==editList}" />
</apex:column>
<apex:column>
<apex:facet name="header">Type</apex:facet>
<apex:outputField value="{!account.Type}" rendered="{!account.id!=editList}" />
<apex:inputField value="{!account.Type}" rendered="{!account.id==editList}" />
</apex:column>
<apex:column>
<apex:facet name="header">Description</apex:facet>
<apex:outputField value="{!account.Description}" rendered="{!account.id!=editList}" />
<apex:inputField value="{!account.Description}" rendered="{!account.id==editList}" />
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:actionFunction action="{!deleteAccount}" name="deleteAccount" reRender="form">
<apex:param name="accountid" value="" assignTo="{!selectedAccountId}" />
</apex:actionFunction>
</apex:form>
</apex:page>

Apex Class Controller:
Public class AccountListController{
 Public list<Account> accList{get;set;}
 Public  Id editList{get;set;}
 Public String selectedAccountId{get;set;}
 Public list<Account> duelist{get;set;}
 Public list<Account> CandidateList{get;set;}
 Public AccountListController(ApexPages.StandardController controller){
  accList = new list<Account>();
  accList =[SELECT Id, Name, Type, Description FROM Account limit 100];
 System.debug('----------->'+accList);
   }
Public void saveRecord(){
  Update accList;
  editList = null;
}
Public PageReference deleteAccount(){
 If(selectedAccountId == Null){
 System.debug('selectedAccountId---->'+selectedAccountId);
}
Else{
Account ac=[select id from Account where id =:selectedAccountId];
 Delete Ac;
}
PageReference prof = new PageReference('/apex/AccountListVFpage');
  Prof.setRedirect(true);
  Return prof;
 }
}
In above controller, you can show account record as per your requirement.
I hope it will help you.
Regards,
Akshay
Dilip KulkarniDilip Kulkarni
Thanks Akshay .I will check and let you know.
Dilip KulkarniDilip Kulkarni
Thanks Ankur. I will check and revert.
Dilip KulkarniDilip Kulkarni
Hi Akshay,
I am getting error  'AccountListController Compile Error: Illegal assignment from List<Account> to List<Account>'  at line  accList = new list<Account>();  in the class. Please help
Dilip KulkarniDilip Kulkarni
Hi Akshay,
I solved the above error by putting 'Schama.Account' in class names. The page is saved and created.
But when I click edit it gives error as below:

'When referencing account.name with inputField, you must select isPersonAccount in your SOQL query'

How to rectify this.