You need to sign in to do that
Don't have an account?
Mallik Vemugunta
Working with Wizards example
Hi I am trying to pass values from one page to another with wizard sample project, but I am getting error because sprint.Project__c is null, can some one look into this. I looked into the view state to confirm sprint.Project__c is null. Also I would like to know how to use system.debug messages to navigate the program flow.
public class ProjectCreateExtension {
private ApexPages.StandardController sc;
public Project__c project {get; set;}
public Sprint__c sprint {get; set;}
public List<Sprint__c> sprints {get; set;}
public ProjectCreateExtension(ApexPages.StandardController controller) {
sc = controller;
project = new Project__c();
sprint = new Sprint__c();
sprints = new List<Sprint__c>();
}
public PageReference ToPage1() {
return Page.ProjectCreate1;
}
public PageReference ToPage2() {
if(ApexPages.CurrentPage().GetURL().StartsWith('/apex/CreateProject1')) {
System.debug('before saveeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee');
sc.save();
}
return Page.ProjectCreate2;
}
public PageReference SaveSprint() {
Project__c project = (Project__c)sc.GetRecord();
sprint.Project__c = Project.Id;
insert sprint;
sprints.Add(sprint);
sprint = new Sprint__c();
return null;
}
}
ProjectCreate1
<apex:page standardController="Project__c" title="Project Creation" extensions="ProjectCreateExtension">
<apex:form >
<apex:PageBlock title="Project Details">
<apex:pageMessages />
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Continue" action="{!ToPage2}"/>
<apex:commandButton value="save" action="{!save}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Enter Project data">
<apex:inputField value="{!Project__c.Name}"/>
<apex:inputField value="{!Project__c.Start_Date__c}"/>
<apex:inputField value="{!Project__c.Budget__c}"/>
</apex:pageBlockSection>
</apex:PageBlock>
</apex:form>
</apex:page>
ProjectCreate2
<apex:page standardController="Project__c" title="Project Creation" extensions="ProjectCreateExtension">
<apex:form >
<apex:PageBlock title="Sprint Details">
<apex:pageMessages />
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Project Details" action="{!ToPage1}"/>
<apex:commandButton value="Save Sprint" action="{!SaveSprint}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Enter Project data">
<apex:inputField value="{!Sprint.Name}"/>
<apex:inputField value="{!Sprint.Start_Date__c}"/>
<apex:inputField value="{!Sprint.End_Date__c}"/>
<apex:outputText value="{!sprint.Project__c}"></apex:outputText>
</apex:pageBlockSection>
<apex:pageBlockTable value="{!sprints}" var="s">
<apex:column value="{!s.name}"/>
<apex:column value="{!s.Start_Date__c}"/>
<apex:column value="{!s.End_Date__c}"/>
<apex:column value="{!s.Project__c}"/>
</apex:pageBlockTable>
</apex:PageBlock>
</apex:form>
</apex:page>
public class ProjectCreateExtension {
private ApexPages.StandardController sc;
public Project__c project {get; set;}
public Sprint__c sprint {get; set;}
public List<Sprint__c> sprints {get; set;}
public ProjectCreateExtension(ApexPages.StandardController controller) {
sc = controller;
project = new Project__c();
sprint = new Sprint__c();
sprints = new List<Sprint__c>();
}
public PageReference ToPage1() {
return Page.ProjectCreate1;
}
public PageReference ToPage2() {
if(ApexPages.CurrentPage().GetURL().StartsWith('/apex/CreateProject1')) {
System.debug('before saveeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee');
sc.save();
}
return Page.ProjectCreate2;
}
public PageReference SaveSprint() {
Project__c project = (Project__c)sc.GetRecord();
sprint.Project__c = Project.Id;
insert sprint;
sprints.Add(sprint);
sprint = new Sprint__c();
return null;
}
}
ProjectCreate1
<apex:page standardController="Project__c" title="Project Creation" extensions="ProjectCreateExtension">
<apex:form >
<apex:PageBlock title="Project Details">
<apex:pageMessages />
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Continue" action="{!ToPage2}"/>
<apex:commandButton value="save" action="{!save}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Enter Project data">
<apex:inputField value="{!Project__c.Name}"/>
<apex:inputField value="{!Project__c.Start_Date__c}"/>
<apex:inputField value="{!Project__c.Budget__c}"/>
</apex:pageBlockSection>
</apex:PageBlock>
</apex:form>
</apex:page>
ProjectCreate2
<apex:page standardController="Project__c" title="Project Creation" extensions="ProjectCreateExtension">
<apex:form >
<apex:PageBlock title="Sprint Details">
<apex:pageMessages />
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Project Details" action="{!ToPage1}"/>
<apex:commandButton value="Save Sprint" action="{!SaveSprint}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Enter Project data">
<apex:inputField value="{!Sprint.Name}"/>
<apex:inputField value="{!Sprint.Start_Date__c}"/>
<apex:inputField value="{!Sprint.End_Date__c}"/>
<apex:outputText value="{!sprint.Project__c}"></apex:outputText>
</apex:pageBlockSection>
<apex:pageBlockTable value="{!sprints}" var="s">
<apex:column value="{!s.name}"/>
<apex:column value="{!s.Start_Date__c}"/>
<apex:column value="{!s.End_Date__c}"/>
<apex:column value="{!s.Project__c}"/>
</apex:pageBlockTable>
</apex:PageBlock>
</apex:form>
</apex:page>
You're re-initializing sprint, and removing the reference to Project__c you set earlier in the method. Try removing that line (or commenting it out) to see if it fixes your issue.
To utilize debug logs:
in the bleow lines Projectid is null that was created in before page. I guess the previous page is not inserting Project record (sc.save(); is not working)
Project__c project = (Project__c)sc.GetRecord();
sprint.Project__c = Project.Id;