+ Start a Discussion

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?

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