1

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?

1

2 Answers 2

0

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.

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

This will occur if the user running the anonymous apex does not have the necessary permissions to read the field. Check the field level security and make it either readable or editable for the affected user/profile.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .