You need to sign in to do that
Don't have an account?

How do I go about writting test class for this
This code works for my requirement but I need test class please.
trigger NoDeleteonTask on Task (before delete)
{
String ProfileId = UserInfo.getProfileId();
List<Profile> profiles=[select id from Profile where name='Profile 1' or name='Profile 2'];
if (2!=profiles.size())
{
// unable to get the profiles - handle error
}
else
{
for (Task a : Trigger.old)
{
if ( (profileId==profiles[0].id) || (profileId==profiles[1].id) )
{
a.addError('You can't delete this record');
}
}
}
}
trigger NoDeleteonTask on Task (before delete)
{
String ProfileId = UserInfo.getProfileId();
List<Profile> profiles=[select id from Profile where name='Profile 1' or name='Profile 2'];
if (2!=profiles.size())
{
// unable to get the profiles - handle error
}
else
{
for (Task a : Trigger.old)
{
if ( (profileId==profiles[0].id) || (profileId==profiles[1].id) )
{
a.addError('You can't delete this record');
}
}
}
}
Test
All Answers
Use this, Some tweaks to this should cover your code.
https://salesforce.stackexchange.com/questions/135454/how-to-write-a-test-class-for-task
PS: Make sure you're wrapping test.startTest(); and test.stopTest(); around Delete Task;
Test
However, on line 41: System.assert(e.getMessage().contains('You can\'t delete this record'));
I got the following error while trying to deploy to production
System.AssertException: Assertion Failed
Stack Trace: Class.TaskdeletionTest.testinsertuser: line 41, column 1