You need to sign in to do that
Don't have an account?
Siddharth Lakhotia
Please help in writting a test class for this trigger? I am new to developement
trigger TaskTrigger on Task (before delete)
{
if(RecursionControl.TaskrunOnce())
{
TaskTriggerHandler.execute(Trigger.old, Trigger.OldMap, Trigger.IsDelete, Trigger.IsBefore);
//The logic is contained in the execute() method of TaskTriggerHandler Class
}
Task Trigger Handler Class
public class TaskTriggerHandler
{
public static void execute(List<Task> oldList, Map<Id, Task> mapOld, Boolean IsDelete, Boolean IsBefore)
{
/* Activate/Deactivate Trigger by Custom Setting "disableRules__c" */
disableRules__c theCustomSetting = disableRules__c.getInstance(UserInfo.getUserId());
if(!(String.IsNotBlank(theCustomSetting.Trigger_Objects__c) && theCustomSetting.Trigger_Objects__c.containsIgnoreCase('Task') && theCustomSetting.Disable_Triggers__c))
{
for(Task oldObj : oldList)
{
oldObj.addError(Label.ActivityDelError);
}
}
}
}
}
{
if(RecursionControl.TaskrunOnce())
{
TaskTriggerHandler.execute(Trigger.old, Trigger.OldMap, Trigger.IsDelete, Trigger.IsBefore);
//The logic is contained in the execute() method of TaskTriggerHandler Class
}
Task Trigger Handler Class
public class TaskTriggerHandler
{
public static void execute(List<Task> oldList, Map<Id, Task> mapOld, Boolean IsDelete, Boolean IsBefore)
{
/* Activate/Deactivate Trigger by Custom Setting "disableRules__c" */
disableRules__c theCustomSetting = disableRules__c.getInstance(UserInfo.getUserId());
if(!(String.IsNotBlank(theCustomSetting.Trigger_Objects__c) && theCustomSetting.Trigger_Objects__c.containsIgnoreCase('Task') && theCustomSetting.Disable_Triggers__c))
{
for(Task oldObj : oldList)
{
oldObj.addError(Label.ActivityDelError);
}
}
}
}
}
All Answers
Thanks a lot for the code sharing.. Can you also tell how do I check code coverage for it
trigger preventTaskDeletion on Task (before delete) {
for(Task tsk: trigger.old){
if(tsk.Status == 'Completed'){
tsk.adderror('Closed Task can not be deleted');
}
}
}
You need to run the test class first and then you can check the code coverage by simply going back to your helper class and trigger and at the top of those respective class and trigger you can see their respective code coverage or another method is once you have run the test class simply click on "Developer Console button" and at the bottom right-hand corner you will see the list of all the classes and triggers with their code coverage besides them.
Refer this link for more information- https://help.salesforce.com/articleView?id=000199478&type=1 (https://help.salesforce.com/articleView?id=000199478&type=1 )
In Tasks.. Owner is a mandatory field.
But I am getting this error. Field is not writeable: Task.Owner
How do I get it corrected