+ Start a Discussion

How to implement Edit functionality in VF page

Hi guys,

I am using  a Vf page on lead.

in that iam using a page block section which opens two input fields when u click new button.

when we enter values and save it stores in a data table in the same page .

For ever record iam using edit and del option in the page block table.

when i click edit  i want use the new button( page block section) but the value should be populated from the selected record.

how to do this.


on  new button:- this page block will open

<apex:pageBlock rendered="{!Property}" id="ref" >

           <apex:pageBlockSection columns="1" >

               <apex:inputField value="{!c.Name}" required="true" />

               <apex:inputField value="{!c.Comments__c}" style="width:380px;height:100px" />


           <apex:pageBlockButtons location="Bottom">

               <apex:commandbutton action="{!Save1}" title="Save" value="Save" />

               <apex:commandbutton action="{!cancel}" title="cancel" value="Cancel" onclick="window.history.previous()" />            </apex:pageBlockButtons>



After entering values it stores the record in this section.

<apex:pageBlock >
<apex:pageBlockTable value="{!Com}" var="p" style="table-layout:fixed;" >

<apex:column width="100px" >
<apex:commandLink value="Edit" action="{!edit1}" reRender="main,ref" >
<apex:param name="cid" value="{!p.id}" assignTo="{!selid}"/>
<apex:commandLink value="Del" action="{!del1}" reRender="main">
<apex:param name="cid" value="{!p.id}" assignTo="{!delid}"/>

<apex:column style="overflow: hidden;">
<apex:facet name="header">Name</apex:facet>

<apex:column style="overflow: hidden;height:20px; ">
<apex:facet name="header">Comments</apex:facet>

<apex:column value="{!p.Role__c}" />
<apex:column value="{!p.Lead__c}" />
<apex:column value="{!p.CreatedDate}" />



When i click edit command link it should open up the top section with the selected record values.and when i save it should update the record.


My controller:-


Public Class lComments{
public lead l {get;set;}
public list<Comments__c> Com{get; set;}
public Comments__c c{get;set;}
public Boolean property {get; set;}
public Boolean hidebutton{get;set;}
public string SelId { get; set; }
public String delid{get;set;}
id str{get;set;}
map<id,String>mpid=new map<id,String>();

public LComments(ApexPages.StandardController controller) {
c=new Comments__c();

public void loaddata(){
com=[select id,name,lead__c
from comments__c
where lead__c=:str order by CreatedDate desc limit 1000];

public PageReference save1(){
Comments__c c=new Comments__c(Name=c.Name,Comments__c=c.comments__c,Lead__c=str);
insert c;
PageReference pageRef = new PageReference(ApexPages.currentPage().getUrl());
return pageRef;

public Comments__c getc(){
c=new comments__c();
return null;
Public comments__c edit1(){
com=[select id,Name,Comments__c,Role__c,Lead__c,createddate from Comments__c where id=:selid];

return null;


public Comments__c del1(){
Com=[select id from comments__c where id=:delid];
delete com;
return null;








And are you hitting problems with your approach?


You can use <apex:inlineEditSupport> and showOnEdit Attribute Name when you click to edit then automatically the save button populate and you can save the record. I think this is you are expecting.    


Hi Bob,


Can u suggest me the best apporach.

I figured out the editing of record .