I have created a trigger on the Account object that is validated only if the records are being created by an non-admin account.
In order to test this functionality I would have to set the createdbyid
field in the test class, but when trying to do this I get the error:
Field is not writeable: Account.CreatedById
I know that for the CreatedDate
field, even though normally is not writable it can be changed in a test environment.
Is the same functionality available for CreatedById
field?
If not, are there any other workarounds that would allow me to test this scenario?
Any help would be much appreciated!
Test.setCreatedDate(a.Id, DateTime.newInstance(2012,12,12));
in test class check sprint 16 release notes releasenotes.docs.salesforce.com/en-us/spring16/release-notes/…