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
PlarentPlarent 

Save function for VisualForce extender is not working

I am having trouble getting the save function to perform update of the object data shown in the table.  I have a table with only 1 editable field.  I want the user to update the field in each row and then press save and the results to refresh.  This is my Visualforce and Apex code.  What am I doing wrong?

 

<apex:page standardController="Tasks__c" recordSetVar="Tasks__c" extensions="TasksByUserID" 
   tabstyle="My_Tasks__tab" sidebar="true">
   <apex:form > 
   <apex:pageBlock title="Hello {!$User.FirstName}!  Here are your tasks">
   <apex:pageMessages />
   <apex:pageBlockButtons >
      <apex:commandButton value="Save" action="{!save}"/>  
   </apex:pageBlockButtons>

   <apex:pageBlockTable value="{!tasks}"  var="tsk">
      <apex:column value="{!tsk.name}"/>     
      <apex:column value="{!tsk.AGN_Employee_Change__c}"/>
      <apex:column value="{!tsk.Application__c}"/>
      <apex:column value="{!tsk.Date_Due__c}"/>
      
      <apex:column headerValue="Current Status">
         <apex:inputField value="{!tsk.Current_Status__c}"/>
      </apex:column>

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

  The extender code is here:

 

public with sharing class TasksByUserID {

    private List<Tasks__c> userTasks;
    
    public TasksByUserID(ApexPages.StandardSetController controller) {

        this.userTasks = (List<Tasks__c>)controller.getRecords();

    }
      
        public ApexPages.StandardSetController taskRecords{
        get {
            if(taskRecords == null) {
                return new ApexPages.StandardSetController(
                         Database.getQueryLocator(
                [SELECT name, Action_to_Perform__c, AGN_Employee_Change__c, Application__c, Date_Due__c,
                Current_Status__c FROM Tasks__c WHERE Owner.id =:Userinfo.getUserId()]));
            }
            return taskRecords;
        }
        private set;
    }

    
    public PageReference save() {
        update this.userTasks;
        return page.AssignedTasks;
    }
    
    public List<Tasks__c> getTasks() {
         return (List<Tasks__c>) taskRecords.getRecords();
    }  
    
}

 

MagulanDuraipandianMagulanDuraipandian

Change the method name to sav instead of save and then try.

 

Cheers!!!

 

Regards,

Magulan D

Salesforce.com certified Force.com Developer.

SFDC Blog

SFDC Site

If this post is your solution, kindly mark this as the solution.

PlarentPlarent

Thanks for you reply!

 

Still nothing.  When I press Save there is a refresh but no editing has taken place.  Any other ideas?

 

bob_buzzardbob_buzzard

There's no problem with the name of the action method - the docs state that if you have a method in your extension controller with the same name as that of a standard controller, the extension controller's method will be called.

 

Looking at your code, I can see a potential disconnect, in that the usertasks is set in the constructor from the parent standard set controller, but when you retrieve the tasks to display, you access the taskRecords property.  As you never set the taskRecords property, it will be null, which means that you create a new instance and retrieve records from the database.  However, you don't store these records anywhere.

 

When your save method executes, it saves the userRecords, which aren't the records that have been returned by the getTasks method.

 

PlarentPlarent

Thanks for helping out.  Still no luck though.  I changed userTasks in order for it to retrieve the records using the same query as taskRecords but that did not work.  Is there some code you can share?  Thanks!