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
Rajat MahajanRajat Mahajan 

Inline Editing in case of lot of records

Hi All,

 

I am trying to achieve inline editing feature for a requirement.

 

I have a sample code as below :

 

<apex:page standardController="Contact">  
 <apex:form >  
 <apex:pageBlock mode="inlineEdit">  
     <apex:pageBlockButtons >  
     <apex:commandButton action="{!edit}" id="editButton" value="Edit"/>  
     <apex:commandButton action="{!save}" id="saveButton" value="Save"/>  
     <apex:commandButton onclick="resetInlineEdit()" id="cancelButton" value="Cancel"/>  
     </apex:pageBlockButtons>  
 <apex:pageBlockSection >  
     <apex:outputField value="{!contact.lastname}">  
         <apex:inlineEditSupport showOnEdit="saveButton, cancelButton"  
             hideOnEdit="editButton" event="ondblclick"  
             changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>  
     </apex:outputField>  
     <apex:outputField value="{!contact.accountId}"/>  
     <apex:outputField value="{!contact.phone}"/>  
 </apex:pageBlockSection>  
 </apex:pageBlock>  
 </apex:form>  
 </apex:page>

 

The only thing that i have a problem is that in order to change a contact i have to append the url everytime with a contact id.

 

That works only in case of one record.


I have a visual force page, which display lot of contact records in a pageblocksection. How would i pass the id for the record i am editing and saving to this, as i would have many records

 

Could you please help me out with this requirement

 

Thanks,

Rajat.

Best Answer chosen by Admin (Salesforce Developers) 
Navatar_DbSupNavatar_DbSup

Hi,
You can simply use the commandbutton for each Contact record on VF page and pass the contact id by using apex:param tag so that in controller you will get that value.
////////////////////////// VF Page ////////////////////////////
<apex:page controller="relatedCon" id="p1">
<apex:form >
<apex:outputPanel id="Panel1">

<apex:repeat value="{!ConDetail}" var="c" >
<apex:inlineEditSupport showOnEdit="Update"
hideOnEdit="editButton" event="ondblclick"
changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
<!-- <apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton action="{!edit}" id="editButton" value="Edit"/>
<apex:commandButton action="{!Update1}" id="saveButton" value="Save" reRender="opanel1">
<apex:param name="ConId" value="{!c.id}" assignTo="{!ConId}"/></apex:commandbutton>
<apex:commandButton onclick="resetInlineEdit()" id="cancelButton" value="Cancel"/>
</apex:pageBlockButtons>
</apex:pageBlock>-->
<table width="100%" border="0" id="t1">
<tr><td width="25%"><b>Account Name</b></td>
<td width="25%">
<apex:outputField value="{!c.con.accountid}"/>
<!--<apex:inlineEditSupport showOnEdit="Update"
hideOnEdit="editButton" event="ondblclick"
changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/></apex:outputField>-->
</td></tr>
<tr><td width="25%"><b>Contact LastName</b></td>
<td width="25%">
<apex:outputField value="{!c.con.lastname}"/>
<!--<apex:inlineEditSupport showOnEdit="Update"
hideOnEdit="editButton" event="ondblclick"
changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/></apex:outputField>-->
</td></tr>
<tr><td width="25%"><b>Contact ID</b></td>
<td width="25%">
<apex:outputField value="{!c.con.id}"/></td></tr>
</table> <br/>
<center><apex:commandButton value="Update" action="{!Update1}" reRender="p1">
<apex:param name="ConId" value="{!c.con.id}" assignTo="{!ConId}"/>
<apex:param name="IndexId" value="{!c.count}" assignTo="{!IndexId}"/>
</apex:commandButton></center>
<hr/>
</apex:repeat>

</apex:outputPanel>
</apex:form>
</apex:page>
////////////////////////////// Controller //////////////////////////////////
public class relatedCon
{
public list<contact> ConDetail1{get;set;}
public list<wrapCon> ConDetail{get;set;}
public id conId{get;set;}
public integer indexId{get;set;}
public relatedCon()
{
ConDetail=new list<wrapCon>();
ConDetail1=[select id,accountid,lastname from contact where accountid =: ApexPages.currentPage().getParameters().get('id')];
system.debug('@@@@@@@@@@@@@@@@' +ConDetail1.size());
integer count=0;
for(contact w : ConDetail1)
{
ConDetail.add(new wrapCon(w,count));
count++;

}
system.debug('%%%%%%%%%%%%%%%%%%%%%%%' +ConDetail);
}
public void Update1()
{
system.debug('@@@@@@@@-------0th last--------@@@@@@@@@' +ConDetail[0].con.lastname);
system.debug('@@@@@@@@-------1st last--------@@@@@@@@@' +ConDetail[1].con.lastname);
system.debug('@@@@@@@@-------2nd last--------@@@@@@@@@' +ConDetail[2].con.lastname);
system.debug('@@@@@@@@@@@@@@@@@' +conId);
contact con2=new contact(id=conId);
// wrapCon w=new wrapCon(con2);
con2.lastname=ConDetail[indexId].con.lastname;
// system.debug(
con2.accountid=ConDetail[indexId].con.accountid;
update con2;
}
public void edit()
{
}
public class wrapCon
{
public contact con{get;set;}
public integer count{get;set;}
public wrapCon(contact con1,integer count)
{
con=con1;
this.count=count;
}
public wrapCon()
{
}
}
}

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

All Answers

Navatar_DbSupNavatar_DbSup

Hi,
You can simply use the commandbutton for each Contact record on VF page and pass the contact id by using apex:param tag so that in controller you will get that value.
////////////////////////// VF Page ////////////////////////////
<apex:page controller="relatedCon" id="p1">
<apex:form >
<apex:outputPanel id="Panel1">

<apex:repeat value="{!ConDetail}" var="c" >
<apex:inlineEditSupport showOnEdit="Update"
hideOnEdit="editButton" event="ondblclick"
changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
<!-- <apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton action="{!edit}" id="editButton" value="Edit"/>
<apex:commandButton action="{!Update1}" id="saveButton" value="Save" reRender="opanel1">
<apex:param name="ConId" value="{!c.id}" assignTo="{!ConId}"/></apex:commandbutton>
<apex:commandButton onclick="resetInlineEdit()" id="cancelButton" value="Cancel"/>
</apex:pageBlockButtons>
</apex:pageBlock>-->
<table width="100%" border="0" id="t1">
<tr><td width="25%"><b>Account Name</b></td>
<td width="25%">
<apex:outputField value="{!c.con.accountid}"/>
<!--<apex:inlineEditSupport showOnEdit="Update"
hideOnEdit="editButton" event="ondblclick"
changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/></apex:outputField>-->
</td></tr>
<tr><td width="25%"><b>Contact LastName</b></td>
<td width="25%">
<apex:outputField value="{!c.con.lastname}"/>
<!--<apex:inlineEditSupport showOnEdit="Update"
hideOnEdit="editButton" event="ondblclick"
changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/></apex:outputField>-->
</td></tr>
<tr><td width="25%"><b>Contact ID</b></td>
<td width="25%">
<apex:outputField value="{!c.con.id}"/></td></tr>
</table> <br/>
<center><apex:commandButton value="Update" action="{!Update1}" reRender="p1">
<apex:param name="ConId" value="{!c.con.id}" assignTo="{!ConId}"/>
<apex:param name="IndexId" value="{!c.count}" assignTo="{!IndexId}"/>
</apex:commandButton></center>
<hr/>
</apex:repeat>

</apex:outputPanel>
</apex:form>
</apex:page>
////////////////////////////// Controller //////////////////////////////////
public class relatedCon
{
public list<contact> ConDetail1{get;set;}
public list<wrapCon> ConDetail{get;set;}
public id conId{get;set;}
public integer indexId{get;set;}
public relatedCon()
{
ConDetail=new list<wrapCon>();
ConDetail1=[select id,accountid,lastname from contact where accountid =: ApexPages.currentPage().getParameters().get('id')];
system.debug('@@@@@@@@@@@@@@@@' +ConDetail1.size());
integer count=0;
for(contact w : ConDetail1)
{
ConDetail.add(new wrapCon(w,count));
count++;

}
system.debug('%%%%%%%%%%%%%%%%%%%%%%%' +ConDetail);
}
public void Update1()
{
system.debug('@@@@@@@@-------0th last--------@@@@@@@@@' +ConDetail[0].con.lastname);
system.debug('@@@@@@@@-------1st last--------@@@@@@@@@' +ConDetail[1].con.lastname);
system.debug('@@@@@@@@-------2nd last--------@@@@@@@@@' +ConDetail[2].con.lastname);
system.debug('@@@@@@@@@@@@@@@@@' +conId);
contact con2=new contact(id=conId);
// wrapCon w=new wrapCon(con2);
con2.lastname=ConDetail[indexId].con.lastname;
// system.debug(
con2.accountid=ConDetail[indexId].con.accountid;
update con2;
}
public void edit()
{
}
public class wrapCon
{
public contact con{get;set;}
public integer count{get;set;}
public wrapCon(contact con1,integer count)
{
con=con1;
this.count=count;
}
public wrapCon()
{
}
}
}

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

This was selected as the best answer
Rajat MahajanRajat Mahajan

Hi

 

Thanks for the response :)

 

As a matter of fact, i had solved it some time back on my own

 

Thanks though,

Rajat

Rajat MahajanRajat Mahajan

Hi,

 

Could you please also publish a code showing how to implement inline edit in case of a list shown in a pageblocksection rather than the repeat tag ?

 

Thanks in advance

Rajat