You need to sign in to do that
Don't have an account?
ChickenOrBeef
How to set CreatedById and CreatedDate for test class records?
Hey everyone,
I need to write a test class for a trigger that heavily involves the CreatedById and CreatedDate of a task. I can't input values for these fields in a test class, since they're not writeable.
How can I set the CreatedById and CreatedDate for the insertion of a task record in a test class?
Thanks!
-Greg
I need to write a test class for a trigger that heavily involves the CreatedById and CreatedDate of a task. I can't input values for these fields in a test class, since they're not writeable.
How can I set the CreatedById and CreatedDate for the insertion of a task record in a test class?
Thanks!
-Greg
Also - As of Spring '16, you can now set the Created date of a record in test context with test.setCreatedDate(recordId, createdDatetime)
http://docs.releasenotes.salesforce.com/en-us/spring16/release-notes/rn_apex_new_classes_methods.htm#rn_apex_new_classes_methods_changed_classes (http://http://docs.releasenotes.salesforce.com/en-us/spring16/release-notes/rn_apex_new_classes_methods.htm#rn_apex_new_classes_methods_changed_classes)
All Answers
reference:
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_dml_non_mix_sobjects_test_methods.htm
Also - As of Spring '16, you can now set the Created date of a record in test context with test.setCreatedDate(recordId, createdDatetime)
http://docs.releasenotes.salesforce.com/en-us/spring16/release-notes/rn_apex_new_classes_methods.htm#rn_apex_new_classes_methods_changed_classes (http://http://docs.releasenotes.salesforce.com/en-us/spring16/release-notes/rn_apex_new_classes_methods.htm#rn_apex_new_classes_methods_changed_classes)