You need to sign in to do that
Don't have an account?
Save error: Index: 0
Im receiving the following error when attempting to save the following VisualForce page. Does anybody have any suggestions? Im stumped.
Thanks in advance
VF Page
<apex:page controller="editNewProjectExt" sidebar="false" showheader="false"> <apex:form > <apex:pageBlock title="Edit new project information" id="newproj" mode="edit"> <apex:pageBlockSection columns="2"> <apex:outputLabel value="Project Name"/> <apex:inputField value="{!myProject.Name}"/> <apex:outputLabel value="Account" /> <apex:inputField value="{!myProject.Account__c}" /> <apex:outputLabel value="Original Completion Date" for="OCDInput"/> <apex:inputField id="OCDInput" value="{!myProject.Original_Completion_Date__c}"/> </apex:pageBlockSection> <apex:pageBlockButtons > <apex:commandButton action="{!saveChanges}" value="Save" /> <apex:commandButton action="{!getupdCaseList}" value="Update Cases" /> </apex:pageBlockButtons> </apex:pageBlock> </apex:form> </apex:page>
Controller
public class editNewProjectExt{ Project_KA__c myProject; integer dayOffset = 0; date OCD=date.Today(); // Orginal completion date of new project date TCD=date.Today(); // Target completion date of new project, stores the user input from VF page on new orginal completion date List<Case> myCaseList; private final ApexPages.StandardController controller; public editNewProjectExt(ApexPages.StandardController controller){ this.controller = controller; myProject = (Project_KA__c)controller.getRecord(); myProject = [select Id, Name, Account__c, Target_Completion_Date__c, Original_Completion_Date__c from Project_KA__c where Id = :myProject.Id]; } // Getter public Project_KA__c getmyProject() { return myProject; } // Save method public pagereference saveChanges() { // myProject.Original_Completion_Date__c=OCDVF.Original_Completion_Date__c; update myProject; PageReference pageRef = new PageReference('/' + myProject.Id); pageRef.setRedirect(true); List<Case> myCaseList = getupdCaseList(); return pageRef; } // Calc new days public List<Case> getupdCaseList(){ if(myProject.Id<>Null){ myCaseList = [select Id, Date_Du__c, Internal_Date_Due__c from Case where Project__c = :myProject.Id]; // Set date veriables OCD= myProject.Original_Completion_Date__c; TCD= myProject.Target_Completion_Date__c; OCD=date.Today(); // loop through and update case details system.debug('OCD = '+OCD); system.debug('TCD = '+TCD); dayOffset = OCD.daysBetween(TCD); system.debug(dayOffset); for(Case myCaseListItem:myCaseList) { Case newCase = myCaseListItem; newCase.Date_Du__c = myCaseListItem.Date_Du__c + dayOffset; newCase.Internal_Date_Due__c = myCaseListItem.Internal_Date_Due__c + dayOffset; upsert newCase; } //for loop } // myClaseList select return null; // do not return anythign out of this method PageReference('/?id='+myProject.Id); } // getmyCalseList method } // For the class
Your page is using a custom controller. The custom controller constructor doesn't take the ApexPages.StandardController as an argument. Remove that (and references to it) and you'll be fine.
All Answers
I spoke to a pretty high up developer contact of mine at SFDC and he said it looked like a VF bug. I've opened a ticket on it and expect to hear back today. I'll let you know what I find out.
I am also seeing this problem - the controller is about the simplest you can possibly have, and the page simply references the controller - no content. It seems to be adding the controller to the page that causes the problem in my case:
<apex:page controller="StoreAppointmentController"></apex:page>
public class StoreAppointmentController { // The extension constructor initializes the private member // variable acct by using the getRecord method from the standard // controller. public StoreAppointmentController(ApexPages.StandardController stdController) { } }
Your page is using a custom controller. The custom controller constructor doesn't take the ApexPages.StandardController as an argument. Remove that (and references to it) and you'll be fine.
As I wanted to keep the constructor that receives the standard controller as a parameter, the more convenient solution was creating a constructor which receives no parameters.
It solved the problem as well.