Thursday, July 29, 2021

Date.ValueOf not accepting null

 String str = null;

 Date d = Date.valueOf(str);

I am getting the following error when running the above snippet in Anon Apex.


Line: 2, Column: 1


System.NullPointerException: Argument cannot be null.


Resolution:  Using Ternary Operator we can fix the null check

Date d = String.isBlank(str)  ?  null  : Date.valueOf(str);

No comments:

Post a Comment

CSS Styling

Styling: 1. Inline Styling: < div style = "font-size: 2rem;font-weight: 400;" > Good Evening </ div > 2. Usi...