3

Here I have 3 VF Pages (ProjectCreate1, ProjectCreate2, ProjectCreate3) and i'm using an extension (ProjectCreationextension) for Standard Controller.

The Error is at line 70, saying that the variable selectedSprint as NULL. But, I tried checking Debug logs by using system.debug and the variable is holding the Id value that has to hold.

Here is my controller

public class ProjectCreationExtension {

private ApexPages.StandardController sc;

public Sprint__c sprint {get; set;}
public List<Sprint__c> sprints {get; set;}

public String selectedSprint {get; set;}

public Story__c story {get; set;}
public List<Story__c> stories {get; set;}

public ProjectCreationExtension (ApexPages.StandardController StandardController) {

    //Store a reference to the standard controller
    sc = standardController;

    //create a new sprint instance to collect user input
    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().ToLowerCase().StartsWith('/apex/projectcreate1')){

        //Save code will go here
        sc.save();

    }

    return Page.ProjectCreate2;

}

public PageReference ToPage3() {

    stories = [SELECT Id, Theme__c, Points__c, Story__c FROM Story__c WHERE Sprint__c = :selectedSprint];
    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;

}

public PageReference SaveStory() {


    system.debug('selected sprint Id is :' +selectedSprint);

    story.Sprint__c = SelectedSprint;

    insert story;

    stories.Add(story);
    story = new Story__c();

    return null;

}

}

There are total of 3 objects involved here: Project, Sprint, Story

Guys, let me know if you need to have a look at VF pages also.

As it looks heavy, if I post everything here, I stopped with controller.

4
  • try to check for null before your story.Sprint__c = SelectedSprint; this statement like : if(String.isNotBlank(SelectedSprint)) Jul 3, 2015 at 12:09
  • Are you sure the problem isn't that story is null? That would cause a NullPointerException.
    – Keith C
    Jul 3, 2015 at 12:13
  • @Aryan Kapoor Yeah i tried that too and its going inside the if loop and printing the value.
    – Krishna N
    Jul 3, 2015 at 12:37
  • @Keith C Yeah, It is not NULL.
    – Krishna N
    Jul 3, 2015 at 12:38

2 Answers 2

0

Story is never initialized, and is null. Initialize it in whichever function navigates to the page that allows the user to insert new stories, or in your constructor.

1
  • Yeah that was extremely perfect. I'm wondering how could i missed that man. Really thanks for your time. Phew!!!
    – Krishna N
    Jul 3, 2015 at 12:43
1

you use this variable 2 times in this code and i think this variable is null where you are executing query: please check in ToPage3() method is it null or not.

stories = [SELECT Id, Theme__c, Points__c, Story__c FROM Story__c WHERE Sprint__c = :selectedSprint];

please check here it should not be null.

Please put this line of code in your constructor story = new story__c();

4
  • Even there also it is not NULL. it holds value in ToPage3() method also..
    – Krishna N
    Jul 3, 2015 at 12:34
  • can you please write only line no 70 in which showing error..... Jul 3, 2015 at 12:35
  • put story = new story__c(); in your constructor Jul 3, 2015 at 12:41
  • Yeah man. Now it is cleared. I haven't initialized story. Thanks for your time. You gave the correct answer but, as SFDCFOX gave the answer earlier, so I have to accept his answer as correct. Don't take it wrong.
    – Krishna N
    Jul 3, 2015 at 12:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .