You need to sign in to do that
Don't have an account?
Simple test class for apex trigger on task
I'm just learning the basics of Apex, and I could use a little help writing a test class for a basic trigger I have that prevents users from deleting tasks. I've been at this for over a week now, and I've just hit a wall with it.
Could anyone help me out with a test class for this? I'll be sure to make it best answer :)
Thanks in advance.
Could anyone help me out with a test class for this? I'll be sure to make it best answer :)
Thanks in advance.
trigger NoDeleteOnTask on Task (before delete) { if(trigger.isDelete){ Set<Id> allowedProfileIds = new Set<Id>(); for(Profile p :[SELECT Id FROM Profile WHERE (Name = 'System Administrator' )]){ allowedProfileIds.add(p.Id); } for (Task a : Trigger.old){ if(!allowedProfileIds.contains(UserInfo.getProfileId())){ a.addError('Task\'s can\'t be deleted. Please contact the system administrator if you require further assistance.'); } } } }
All Answers
Let me know if anything.
Wil,