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
Jean Grey 10Jean Grey 10 

Null Pointer Exception Error from new lines of code

I've added just a few lines of code for time zone handling and the page is now throwing an error on submit.

I added these lines in the submit method:
User-added image

adjustment is a public variable declared in the top of the code. 

Here is my error from the log (screenshot):
User-added image
Best Answer chosen by Jean Grey 10
Zuinglio Lopes Ribeiro JúniorZuinglio Lopes Ribeiro Júnior
Hello Jean,

Place a system debug before line 248 to make sure your fields and variables has value and are not null:
system.debug(o.Director__r.TimeZoneSidKey);
system.debug(apptdate);

Hope to have helped!

Regards.

Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.

All Answers

Zuinglio Lopes Ribeiro JúniorZuinglio Lopes Ribeiro Júnior
Hello Jean,

Place a system debug before line 248 to make sure your fields and variables has value and are not null:
system.debug(o.Director__r.TimeZoneSidKey);
system.debug(apptdate);

Hope to have helped!

Regards.

Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.
This was selected as the best answer
Zuinglio Lopes Ribeiro JúniorZuinglio Lopes Ribeiro Júnior
If they are null you should consider revising your code, the data, or skipping this part of the code when there is no value.
Jean Grey 10Jean Grey 10
Thank you, I debugged and saw that the Director TimeZoneSidKey is null, but the Director is not null and I can see in the user data that the timezone is populated. How is this possible?
Amit Chaudhary 8Amit Chaudhary 8
Please check if condition before 248 line
if( o.Director__C.TimeZoneSidKey !=null)
Let us know if this will help you
 
Zuinglio Lopes Ribeiro JúniorZuinglio Lopes Ribeiro Júnior
Hello Jean,

Director is a lookup for the User sObject right? Can you please share your query? I also suggest you to run the same query in the Developer Console to see if it's working as expected.

Hope to have helped!

Regards.

Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.
 
Jean Grey 10Jean Grey 10
I was able to resolve this by accessing the user timezonesidkey via query before the code I added. Thank you for your help!
Zuinglio Lopes Ribeiro JúniorZuinglio Lopes Ribeiro Júnior
Here to help Jean! I'm glad it worked! 

​Regards