• Greg Montgomery
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Background:
Although I have coded, it's been in the mainframe world and, thus, I have no experience in Apex.  I went through the tutorial (Visualforce Workbook) and now am in the associated thicker book (Visualforce in Practice).  In Chapter 5 (Building Wizards), the exercise is to code three pages which call each other.  In a nutshell, you enter data about the parent and, when you click Continue, it saves the record and takes you to page 2 where you enter information about the child.  (Page 3 is about grandchildren--same idea--but I'm not there yet).  The three tables are related with a Master-Detail field.

Problem:
Page 1 information is saved and takes me to page 2.  When I click on Save, it's supposed to get the ID of the parent (it does--it's in the log) and then somehow save the child's record.  I don't think it's getting to that line (failure is indicated on the line after the get and before the insert) but have no clue why.  The errant line is in bold (about ten lines from the bottom).

I'd like to solve this myself but, since I don't know enough to know where to look, I figured I'd try here while I look elsewhere.  I've checked the online version of the book (http://www.developerforce.com/guides/Visualforce_in_Practice.pdf) but it has the same code as the book.  I've searched this forum and Google but no one has posted these exercises and I can't see how to relate posted solutions to this one.

Thanks in advance.

Mke
 

The code:
public class ProjectCreateExtension
{
private ApexPages.StandardController sc;
    public Sprint__c sprint {get; set;}
    public List<Sprint__c> sprints {get; set;}
    public String selectedSprint {get; set;}
   
    public ProjectCreateExtension(ApexPages.StandardController standardController)
    {
        // store a reference to the standard controller
        sc = standardController;
        sprint = new Sprint__c();
        // create a new list to store the sprints added by the user
     sprints = new List<Sprint__c>();
    }
   
    public PageReference ToPage1()
    {
        return Page.ProjectCreate1;
    }

    public PageReference ToPage2()
    {
        if (ApexPages.CurrentPage().GetURL().StartsWithIgnoreCase('/apex/projectcreate1'))
        {
            sc.Save();
            Project__c project = (Project__c)sc.GetRecord();
            sprint.Project__c = project.Id;
            insert sprint;
        }
            return Page.ProjectCreate2;       
    }

    public PageReference ToPage3()
    {
        return Page.ProjectCreate3;
    }
   
    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;
    }
       
}