+ Start a Discussion
@anilbathula@@anilbathula@ 

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:pageBlockSection>

           <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>

        </apex:pageBlock>

-----------------------------------------------------

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>
&nbsp;&nbsp;&nbsp;&nbsp;
<apex:commandLink value="Del" action="{!del1}" reRender="main">
<apex:param name="cid" value="{!p.id}" assignTo="{!delid}"/>
</apex:commandLink>
</apex:column>

<apex:column style="overflow: hidden;">
<apex:facet name="header">Name</apex:facet>
{!If(LEN(p.Name)<25,p.Name,LEFT(p.Name,25))}
</apex:column>

<apex:column style="overflow: hidden;height:20px; ">
<apex:facet name="header">Comments</apex:facet>
{!If(LEN(p.Comments__c)<100,p.Comments__c,LEFT(p.Comments__c,100))}
</apex:column>

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

</apex:pageBlockTable>
</apex:pageBlock>

 

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) {
l=(Lead)controller.getRecord();
str=Apexpages.currentpage().getparameters().get('id');
property=false;
hidebutton=true;
c=new Comments__c();
loaddata();

}
public void loaddata(){
com=[select id,name,lead__c
,Contact__c
,Application__c
,Finance__c
,Comments__c
,lead__r.Name
,Role__c
,CreatedDate
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());
pageRef.setRedirect(true);
return pageRef;
}

public Comments__c getc(){
property=true;
hidebutton=false;
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];
if(com.size()>0){
delete com;
}
loaddata();
return null;
}

}

 

 

 

Thanks

Anil.B

bob_buzzardbob_buzzard

And are you hitting problems with your approach?

jd123jd123

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.    

@anilbathula@@anilbathula@

Hi Bob,

 

Can u suggest me the best apporach.

I figured out the editing of record .

 

Thanks

Anil.B