0

On the visual force page I have a method that is being called by clicking on the command link as follows

<apex:actionRegion>
                    <apex:input type="date" value="{!recurringTaskLPP.endDate}">
                    </apex:input>
                    <apex:commandLink action="{!calculateEndDate}" value="Calculate End Date"
                                      reRender="RecurringDatesSection">
                    </apex:commandLink>
                </apex:actionRegion>

After clicking the command link I have the following method being called on in the controller

 public void calculateEndDate() {
   PageReference pageError = this.checkForErrors();
    if (recurringTaskLPP.getFrequency() == FREQUENCY_TYPE_DAILY) {
        this.calculateEndDateForDailyView();
    }
    if (recurringTaskLPP.getFrequency() == FREQUENCY_TYPE_WEEKLY) {
        this.calculateEndDateForWeeklyView();
    }
    if (recurringTaskLPP.getFrequency() == FREQUENCY_TYPE_MONTHLY) {
        this.calculateEndDateForMonthlyView();
    }
}

public PageReference checkForErrors(){
    if (recurringTaskLPP.recurringAmount == null || recurringTaskLPP.startDate == null || recurringTaskLPP.numberOfLppDetails == null) {
        ApexPages.Message recurringTaskErrorMessage = new ApexPages.Message(ApexPages.Severity.WARNING, 'Amount field and Start Date and Lpp Details Count should not be left empty!');
        ApexPages.addMessage(recurringTaskErrorMessage);
    }
    return null;
}

But the error message never displays and it gives an error that you are trying to De-reference the null object. Can some one please help me in understanding why the error is not displayed and how cna it be resolved.

0

few points. As you are getting attempt to de-reference null object error. So I suggest you to put your code in try catch block

try {
  // code here
}
catch(exception ex)
{

        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.WARNING, ex.getmessage()););
}

And then in the VF page use apex:pageMessages and rerender it to display error message properly.

<apex:pageMessages id="msg"/>
| improve this answer | |
  • It works but since i have to also put it inside an action region this solution is not acceptable . It has to be done with page error so that other functionality can be build on it – Abhinav Pandey Jun 29 '16 at 18:29
  • Solved the issue by just putting everything in one method and checking the error condition with if and other condition with else if . This solves the problem without need of any ID or any other change – Abhinav Pandey Jun 29 '16 at 18:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.