function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
cmarkcmark 

test coverage - dealing with CreatedById

Hello.  I wrote a trigger which prevents Tasks and Events from being deleted by anyone other than their creator.  Code is easy enough - compare the current user with the createdbyid.  The issue is in writing the test code.  How do I create a test for the scenario where the current user and createdbyid are different?

thanks
chris
BoxBox
Hey Chris,

It’s not the nicest way to test your code but i would do the following:

1.    Create a task and/or event which is named something along the lines of “APEX Test Event DO NOT DELETE” and mark it long in the past or future
2.    Create Database rollback point
3.    In test class go looking for this event by date or name and then perform your processing
4.    Rollback (just in case you delete a real event by accident)

As I said it’s not the nicest solution but it would get the scenario required for your test class.



Message Edited by Box on 09-01-2008 04:10 PM