+ Start a Discussion
Nagma KhanNagma Khan 

how to show the each contact record on the visualfroce and each particular record have a button edit and save and delete ?

hi

how to show each contacts on the visualfroce page and each particular record have a button for edit and delete and save  ??

example
id ,lastName,firstName
112222xhd , xyz , yyy              edit ,delete,save
same another records .............. how to possible please suggest me


Thanks
Nagma

 
Ankur Saini 9Ankur Saini 9
Hi Nagma,

You want a visualforce page having list of records in a table with edit, delete and save button ?

Thanks,
Ankur Saini
Nagma KhanNagma Khan
yes  Ankur
GauravGargGauravGarg
Hi Nagma,

You need to use Wrapper class in this case. Please follow below instructions:
  • Create wrapper class for the defined fields to be displayed on VF page. 
  • Populate wrapper with the object records and make is visible (public), always make a field for record ID that will be saved after changes. .
  • Use apex:repeat on VF page and display records and its fields. 
  • Add three custom button links for edit, delete, and save and its handling function on Controller side. 
  • Make a list of records Id, that are modified. 
  • When the final changes are done. On Page save populate the changes on to the object for records being modified. 
Hope this helps!!!

For more info you can directly contact me on skype: gaurav62990

Thanks,
Gaurav 
Ankur Saini 9Ankur Saini 9
Hi Nagma,

Tyr this one

VF 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" id="table">
                <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;
                    <apex:commandLink value="Del" reRender="table" rendered="{!account.id!=editList}" onclick="if (window.confirm('Are you sure?')) deleteAccount('{!account.Id}');"/>
                    <apex:commandLink value="Cancel" reRender="account_list" rendered="{!account.id==editList}" action="{!cancelRecord}"/>
                </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="table">
        <apex:param name="accountid" value="" assignTo="{!selectedAccountId}" />
        </apex:actionFunction>
    </apex:form>
</apex:page>

Class:
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];
   }
   
 Public void saveRecord(){
      Update accList;
      editList = null;
  }
 Public void cancelRecord(){
      editList = null;
 }
 Public void deleteAccount(){
     if(selectedAccountId == Null){
     }
     else{
       Account ac=[select id from Account where id =:selectedAccountId];
         Delete Ac;
         editList = null;
        }
 }
}

Thanks,
Ankur Saini
http://mirketa.com