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
forceappforceapp 

Save on Edit based on particular Record in a Vf page.

My senario is ,I have edit link for every record, when i click the edit of a particular record then edit should be changed to save button, and field values to text boxes of that record only and that record should saved when updated.  

 

The below code works, when edit is clicked, all edit links are converted to save button and field values to text boxes . where it should not happen.  It should  function based on record...

Page:
<apex:page controller="Employ" sidebar="false" showHeader="true" id="pg">

<apex:pageBlock title="Employee List" id="pb2">
<apex:form id="f1" >
 <apex:outputPanel rendered="{!table1}">
<apex:pageBlockTable value="{!emplst}" var="e">
<apex:column headerValue="Action">
  <apex:commandLink value="edit" action="{!edit}"/>
   </apex:column>
<apex:column value="{!e.name}"/>
<apex:column value="{!e.Email__c}"/>
<apex:column value="{!e.Phone__c}"/>
</apex:pageBlockTable>
</apex:outputPanel>

 <apex:outputPanel rendered="{!table2}">
<apex:pageBlockTable value="{!emplst}" var="emp">
<apex:column headerValue="Action">
<apex:commandButton value="save" action="{!save}"/>
</apex:column>
<apex:column ><apex:inputText value="{!emp.name}"/></apex:column>
<apex:column ><apex:inputText value="{!emp.Email__c}"/></apex:column>
<apex:column ><apex:inputText value="{!emp.Phone__c}"/></apex:column>
  
</apex:pageBlockTable>
</apex:outputPanel>

</apex:form>
</apex:pageBlock>
</apex:page>
Controller:

public with sharing class Employ{
    boolean Table1=true;
    boolean Table2=false;


        public void save() {
        table2=false;
        table1=true;
        //system.debug('*************'+emplst);
        update emplst;
               
    }

    public boolean getTable2() {
        return Table2;
    }


  public boolean gettable1(){
 return table1;
 }
 

    public PageReference edit() {
        table1=false;
        table2=true;
        return null;
    }
    List<Employ__c> emplst;
    public List<Employ__c> 
    getemplst(){
    emplst=[select name,id,phone__c,Email__c from Employ__c];
        return emplst;
   }


  }

  --Regards,

    forceapp.

 

Chamil MadusankaChamil Madusanka

Hi,

 

The reason for that behavior is that you are using a pageBlock Table. You want to apply inline edit for pageBlockTable. Am I correct?

 

You can use standard inline editing for pageBlockTable as well. And You can create your own inline edit function.

What are you preferring to do?

forceappforceapp

I am not aware of inline editing, if you know the solution, reply me with code.

 

Thanks in advance.

 

--Regards,

 forceapp.

Chamil MadusankaChamil Madusanka

Hi,

 

Here is an example for inline editing in visualforce. YOu can apply this for a pageBlockTable as well.

 

http://salesforceworld.blogspot.com/2011/06/inline-editing-in-visualforce-page.html

 

If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

 

Chamil's Blog