I have a custom field: Show_DateTime__c which is a formula(Date/time)

When I run the following anonymous apex:

Coverage_Request__c covreq = [Select Show_DateTime__c, name from Coverage_Request__c where name = 'a0Cg0000007URCI'];

system.debug('Show name is ' + covreq.Name);
system.debug('show date time is ' + covreq.Show_DateTime__c);

I get the output:

|DEBUG|Show name is a0Cg0000007URCI
|DEBUG|show date time is null

but when I log into my sandbox and go to the actual record there is a show_DateTime value:

enter image description here

Any suggestions?


I'm going to assume for a moment that Show_DateTime__c is a DateTime data type.

You will need to implicitly convert it to a string for debug purposes....

system.debug(msg) will automatically convert an object to a string using the type's built-in toString() method. The DateTime type does not have a toString() method.

You can use String.valueOf(covreq.Show_DateTime__c) to force the type conversion.

  • If I try and do covreq.Show_DateTime__c.format(); I get a null pointer exception, so it is actually null Sep 11 '17 at 19:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.