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
JosephJJosephJ 

inline edit saving records only for last row of the pagination.

I've created a really simple pagination with search box and created a simple VF page with inline editing on the fields.
Now,depending on what I do between filling in a value in the field and clicking the Save button,it will affect whether the new value is saved or not.

So if I double click on the Last row, amend value, hit enter.The text turns orange and I get the undo icon as expected and Save, it saves the record.But when I edit and click Save for the previous records, the value goes back to its OLD value and is not updated.


Page :

public class PagingTasksController{

    public List<Task> tasks;
    public Integer CountTotalRecords{get;set;}
    public String QueryString {get;set;}
    public Integer OffsetSize = 0;
    private Integer QueryLimit = 3;
    public List<Task> lstTasks;
    public String searchText {get;set;} 
   
    public PagingTasksController (){
        //CountTotalRecords= [select count() from Task];
    }
   


    public List<Task> getTasks(){
        if(tasks == null){
            tasks = new List<Task>();
        }
        return tasks;
    }
   
    public void findTasks(){
        String qStr2 = 'Select count() from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+'%\'';
        CountTotalRecords = Database.countQuery(qStr2);
        queryTasks();
    }
   
    public void  queryTasks(){
        String qStr = 'Select OwnerId,Subject,Status,Priority from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+'%\' Order By Subject,Status limit ' + QueryLimit + ' offset ' + OffsetSize;
        tasks = Database.query(qStr);
        tasks.sort();

    }

    public Boolean getDisablePrevious(){
        if(OffsetSize>0){
            return false;
        }
        else return true;
    }

    public Boolean getDisableNext() {
        if (OffsetSize + QueryLimit < countTotalRecords){
            return false;
        }
        else return true;
    }

    public PageReference Next() {
        OffsetSize += QueryLimit;
        queryTasks();
        return null;
    }

    public PageReference Previous() {
        OffsetSize -= QueryLimit;
        queryTasks();
        return null;
    }

   public PageReference save() {
        update tasks;
        return ApexPages.CurrentPage();
    }
   
}

<apex:page controller="PagingTasksController">
    <apex:form >
        <apex:pageBlock title="Tasks" id="pgBlock">
           <apex:pageBlockButtons >
               <apex:commandButton action="{!save}" id="saveButton" value="Save"/>
               <apex:commandButton onclick="resetInlineEdit()" id="cancelButton" value="Cancel"/>
           </apex:pageBlockButtons>
    
        <apex:inlineEditSupport showOnEdit="saveButton, cancelButton"
                    hideOnEdit="editButton" event="ondblclick"
                    changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
    
       <apex:inputText id="searchBox" value="{!searchText}"/>
        <apex:commandButton value="Search" reRender="pgTable,pgBlock" action="{!findTasks}"/>
        <apex:pageBlockTable value="{!Tasks}" var="tsk" id="pgTable" >
   <apex:column >
  <apex:outputLink value="{!URLFOR($Action.Task.Delete, tsk.id,['retURL'='/apex/task_test'])}" >Delete</apex:outputLink>
</apex:column>
          
                <apex:column value="{!tsk.Subject}"/>
                <apex:column value="{!tsk.Status}"/>
                <apex:column value="{!tsk.Priority}"/>
                <apex:column value="{!tsk.OwnerId}"/>
            </apex:pageBlockTable>
            <apex:pageBlockButtons >
                <apex:commandButton value="Previous" action="{!Previous}" rerender="pgTable,pgBlock"
                                    status="status" disabled="{!DisablePrevious}" />
                <apex:commandButton value="Next" action="{!Next}" reRender="pgTable,pgBlock"
                                    status="status" disabled="{!DisableNext}" />
                <apex:actionStatus id="status" startText="Please Wait..."/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
     <apex:enhancedlist type="Activity" height="800" rowsPerPage="50" customizable="False"/>
</apex:page>

    
Class :


public class PagingTasksController{

    public List<Task> tasks;
    public Integer CountTotalRecords{get;set;}
    public String QueryString {get;set;}
    public Integer OffsetSize = 0;
    private Integer QueryLimit = 3;
    public List<Task> lstTasks;
    public String searchText {get;set;} 
   
    public PagingTasksController (){
        //CountTotalRecords= [select count() from Task];
    }
     public List<Task> getTasks(){
        if(tasks == null){
            tasks = new List<Task>();
        }
        return tasks;
    }
   
    public void findTasks(){
        String qStr2 = 'Select count() from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+'%\'';
        CountTotalRecords = Database.countQuery(qStr2);
        queryTasks();
    }
   
    public void  queryTasks(){
        String qStr = 'Select OwnerId,Subject,Status,Priority from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+'%\' Order By Subject,Status limit ' + QueryLimit + ' offset ' + OffsetSize;
        tasks = Database.query(qStr);
        tasks.sort();

    }

    public Boolean getDisablePrevious(){
        if(OffsetSize>0){
            return false;
        }
        else return true;
    }

    public Boolean getDisableNext() {
        if (OffsetSize + QueryLimit < countTotalRecords){
            return false;
        }
        else return true;
    }

    public PageReference Next() {
        OffsetSize += QueryLimit;
        queryTasks();
        return null;
    }

    public PageReference Previous() {
        OffsetSize -= QueryLimit;
        queryTasks();
        return null;
    }

   public PageReference save() {
        update tasks;
        return ApexPages.CurrentPage();
    }
   
}

Am I coding my inline edit incorrectly? Can you see anything unusual?
Best Answer chosen by JosephJ
Dev.AshishDev.Ashish
Hi James,

It would have been great if you would have provided your response on the original thread where you posted your requirements and I replied :-)

Now for inline edit instead of putting value to column directly you need to output value to outputfield like below.

<apex:column headerValue="Subject">
	<apex:outputField value="{!tsk.Subject}"/>
</apex:column>
<apex:column headerValue="Status">
	<apex:outputField value="{!tsk.Status}"/>
</apex:column>
<apex:column headerValue="Priority">
	<apex:outputField value="{!tsk.Priority}"/>
</apex:column>
<apex:column headerValue="OwnerId">
	<apex:outputField value="{!tsk.OwnerId}"/>
</apex:column>

it shoud resolve the issue you are facing.

All Answers

Dev.AshishDev.Ashish
Hi James,

It would have been great if you would have provided your response on the original thread where you posted your requirements and I replied :-)

Now for inline edit instead of putting value to column directly you need to output value to outputfield like below.

<apex:column headerValue="Subject">
	<apex:outputField value="{!tsk.Subject}"/>
</apex:column>
<apex:column headerValue="Status">
	<apex:outputField value="{!tsk.Status}"/>
</apex:column>
<apex:column headerValue="Priority">
	<apex:outputField value="{!tsk.Priority}"/>
</apex:column>
<apex:column headerValue="OwnerId">
	<apex:outputField value="{!tsk.OwnerId}"/>
</apex:column>

it shoud resolve the issue you are facing.

This was selected as the best answer
JosephJJosephJ
This dd resolve my query.Thanks !. But i've a question , when you click on Search box without entering any values, then also it renders/displays me the values.?  Also when i search for only one letter in search box it displays me all the results which should not . Example, say i want to search for Subject called " Call " and when i type 'c' in the box it gives me other values also ? Any pointers will be helpful. You are champ Dev.Ashish.
Dev.AshishDev.Ashish
James,

Actually searching is done by SOQL only, you have used 'Select OwnerId,Subject,Status,Priority from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+'%\' Order By Subject,Status limit ' + QueryLimit + ' offset ' + OffsetSize;
hence it will search on all fields in where clause for whatever text you provide even single one.
For blank search, it will show all tasks as in SOQL where clause it would return all results.
JosephJJosephJ
But when i click on Search and do not enter any text ,then it should prompt to wirte values ,right ? What do you think or suggest