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
Mallik VemuguntaMallik 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>
James LoghryJames Loghry
I believe your issue is because of the following line in your SaveSprint method:
 
sprint = new Sprint__c();

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:
  1. Add "System.debug('')" statements to your code, like you have already done.
  2. Go to Setup->Monitoring->Debug Logs
  3. Create a debug log for the user you are testing with, for instance if you are logged in and testing your own VF page, then create a debug log user as yourself.
  4. For all you could ever want to know on debug logs, see also: https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_debugging_debug_log.htm
Mallik VemuguntaMallik Vemugunta
Thank You, I had this line sprint = new Sprint__c() to initialize the already entered sprint so new one can be added on tehscrren. Problem I havig is
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;