You need to sign in to do that
Don't have an account?
Nagarjuna Reddy.P
test class for trigger updates field on account
Hi All,
Could any one please provide test class for the following trigger that updates field on account.
apexclass...
public with sharing class CountofTasks{
public static void updateAcc(List<Task> tasks){
set<id> accids = new set<id>();
for(Task t:tasks){
if(t.whatid!=null){
accids.add(t.whatid);
}
}
List<Account> accounts = [select id,Task_Count__c from Account where id in:accids];
integer count = [select count() from Task where whatid in:accids];
if(count >0){
for(Account a:accounts){
a.Task_Count__c = count ;
}
}
update accounts;
}
Trigger...
trigger ExampleTrigger on Task (after insert,after delete) {
if(Trigger.isInsert && Trigger.isAfter){
CountofTasks.updateAcc(Trigger.New);
}
}
Thanks in Advance....
Could any one please provide test class for the following trigger that updates field on account.
apexclass...
public with sharing class CountofTasks{
public static void updateAcc(List<Task> tasks){
set<id> accids = new set<id>();
for(Task t:tasks){
if(t.whatid!=null){
accids.add(t.whatid);
}
}
List<Account> accounts = [select id,Task_Count__c from Account where id in:accids];
integer count = [select count() from Task where whatid in:accids];
if(count >0){
for(Account a:accounts){
a.Task_Count__c = count ;
}
}
update accounts;
}
Trigger...
trigger ExampleTrigger on Task (after insert,after delete) {
if(Trigger.isInsert && Trigger.isAfter){
CountofTasks.updateAcc(Trigger.New);
}
}
Thanks in Advance....
You can refer https://trailhead.salesforce.com/en/content/learn/modules/apex_testing/apex_testing_triggers
Please let me know if still having doubt
thanks
Please use following code it will cover 100% of your code.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com