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
Andreas GerogiannisAndreas Gerogiannis 

Apex class resulting in System.NullPointerException: Attempt to de-reference a null object

Hi all!  Anyone have any ideas on this?

 

I have a forecasting function button in the Opportunity called Establish Schedule that is generating the following error:

 

Visualforce Error


System.NullPointerException: Attempt to de-reference a null object

 

Class.EstablishScheduleController.__sfdc_FirstDate: line 20, column 1
Class.EstablishScheduleController.__sfdc_Year1: line 232, column 1
Class.EstablishScheduleController.__sfdc_Year2Len: line 250, column 1     

 

Here are the lines.  I can't paste the entire code because this site won't let me post that many characters.

 

20)       return objOpportunity.Est_Scheduled_Start_Date__c.toStartOfMonth();

232)     return String.valueOf(FirstDate.year());

250)         if (Year1 == Year2) return 0;

 

I'd be happy to provide the entire code via email or any other means if you can help out.  Thanks!!

Best Answer chosen by Admin (Salesforce Developers) 
hisalesforcehisalesforce

delete line no 20(Code in line no 20)

 

and copy this code:

 

if(objOpportunity.Est_Scheduled_Start_Date__c!=null)

  return objOpportunity.Est_Scheduled_Start_Date__c.toStartOfMonth();

else return null;

 

This should help..

All Answers

hisalesforcehisalesforce

Replace line no 20 with this date.Since Est_Scheduled_Start_Date__c is null ,so was unable to get the start of the month.

This code will check null exception..... 

 

if(objOpportunity.Est_Scheduled_Start_Date__c!=null)

  return objOpportunity.Est_Scheduled_Start_Date__c.toStartOfMonth();

else return null;

Andreas GerogiannisAndreas Gerogiannis
when you say replace, do you mean line 20 should look like this:

20) return objOpportunity.Est_Scheduled_Start_Date__c.09/19/2013(); ?

I'm not a developer so I need a little hand holding. If I'm wrong, can you give me an idea of exactly what the line should look like?

Thank you so much!
hisalesforcehisalesforce

delete line no 20(Code in line no 20)

 

and copy this code:

 

if(objOpportunity.Est_Scheduled_Start_Date__c!=null)

  return objOpportunity.Est_Scheduled_Start_Date__c.toStartOfMonth();

else return null;

 

This should help..

This was selected as the best answer
Andreas GerogiannisAndreas Gerogiannis
That worked! Thank you so much!!!
Andreas GerogiannisAndreas Gerogiannis
Uh oh. For reasons I can't identify, this has stopped working. I now get this error:

Attempt to de-reference a null object
An unexpected error has occurred. Your development organization has been notified.

It worked fine right after I deployed but now it's not... any ideas?