You need to sign in to do that
Don't have an account?
salesforce sfdx
Thanks
Prathusha
Hi team, as fresher in coding got a Sample program to write a test class please help me if you can
public class TaskAccountTriggerHandler { public void afterInsertOrUpdateMethod(List<Task> NewTasks){ List<Case> cList = new List<Case>(); //List collection with case is created to store the case records //values will pass from trigger to here If(!NewTasks.isEmpty()){ for (Task t : NewTasks) { string id = string.valueof(t.WhatId); //condition for Account Related Task If(t.WhatId != null && id.startsWith('001')){ t.Account__C = t.WhatId; //Condition for Case Related Task and startsWith 500 and completed as status. }else If(t.WhatId != null && id.startsWith('500')&&t.Status == 'Completed'){ Case c = new Case(); c.Id = t.whatId; c.Comments='Completed a task: '+t.Subject; cList.add(c); //adding to the list to update } } } //it will check the list empty or not for update. if(!cList.isEmpty()) update cList; } }
trigger TaskAccountTrigger on Task (before insert , before update) { TaskAccountTriggerHandler TaskHandlr = New TaskAccountTriggerHandler(); //Before insert and update if(Trigger.isbefore && Trigger.isinsert ){ TaskHandlr.afterInsertOrUpdateMethod(Trigger.New); } //Before insert and update if(Trigger.isbefore && Trigger.isupdate){ TaskHandlr.afterInsertOrUpdateMethod(Trigger.New); } }Please provide your suggestions or links
Thanks
Prathusha
Can you try the below test class.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
All Answers
Did you try writing a test class by just creating task records and updating them or do you need entire test class?
Thanks,
iam a fresher just need to coverthe test class do you need entire test class
Thanks for your reply
Can you try the below test class.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
Praveen..its worked ..!