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
Yoshinori MoriYoshinori Mori 

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

  

System.NullPointerException: Attempt to de-reference a null object 
Class.AAA.: line 44, column 3 External entry point

 

I got a error message when I open the page on the Salesforce.

 

I create a class as below.

The message is somehow indicating 3rd line "hasseijikoku.kisyou_id__r.ReportDateTime__c = mstDatetime;"

 

public with sharing class  AAA {

 

--------- abbreviation----------------

 

//Constructor

public AAA() {

 

  mstDatetime = Datetime.now();
  hasseijikoku = new WXS_T_PopUpReceipt__c();
  hasseijikoku.kisyou_id__r.ReportDateTime__c = mstDatetime;
       
         }   

 

--------- abbreviation----------------

 

There was no error neither class nor visal force on Eclipse side.

 

I appreciate if anyone could help me find the problem

 

Regards

 

Mori

 

bob_buzzardbob_buzzard

This sounds like the relationship "kisyou_id__r" is evaluating to null.  We could really do with seeing the rest of the code.  For example, how to you construct your "hasseijikoku" instance?

Yoshinori MoriYoshinori Mori

Thank you Bob Buzzard

 

I deleted 3rd line "hasseijikoku.kisyou_id__r.ReportDateTime__c = mstDatetime;"

It works OK.

I just copied those 3 lines from other sources.

I didn't understand why I needed to use them.

 

Thank you for your help

 

May I ask you one more question?

 

I would like to write SOQL to retrieve records that includes only matched ReportDateTime__c with  mstDatetime ( which is = Datetime.now();)

Only records that matched on Date.

Time is not needed.

 

Mori

bob_buzzardbob_buzzard

I think you'd want to do that by matching on a range of date/time, from midnight to midnight.

 

Something like:

 

 

DateTime startDT=DateTime.newInstance(System.today(), Time.newInstance(0,0,0,0));

DateTime endDT=DateTime.newInstance(System.today(), Time.newInstance(0,0,0,0));
endDT.addDays(1);

List<myobj__c> objs=[select id, ReportDateTime__c from myobj__c where ReportDateTime__c >= :startDT and ReportDateTime__c < :endDT];

 

 

Yoshinori MoriYoshinori Mori

Dear bob_buzzard

 

Thank you for your answer to my second question.

I'll try this one.

 

Regards

 

Mori