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

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

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) {
    if (recurringTaskLPP.getFrequency() == FREQUENCY_TYPE_WEEKLY) {
    if (recurringTaskLPP.getFrequency() == FREQUENCY_TYPE_MONTHLY) {

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!');
    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.

1 Answer 1


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"/>
  • 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 Jun 29, 2016 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 Jun 29, 2016 at 18:39

You must log in to answer this question.

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