function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
RahulRahul 

can someone please help with the test class of this code please

trigger updatestatus on Task (after insert) {
set<id> setid = new set<id>();
list<contact> lstcon = new list<contact>();
for(task t :trigger.new){
setid.add(t.whatid);
setid.add(t.whoid);
}
for(contact cc :[select id,boolean__C,(select subject from tasks) from contact where id=:setid]){
For(task t1 :trigger.new){
if(t1.subject=='Mass Email'){
Contact cc1 = new contact();
cc1.id=cc.id;
cc1.boolean__c='True';
lstcon.add(cc1);

}
update lstcon;
}

}

}
Best Answer chosen by Rahul
RKSalesforceRKSalesforce
Hi Sumit,

Hope Below Test Class will work:
@isTest 
private class SampleTestClass {
    static testMethod void validateContactsAndTasks() {
       Contact con = new Contact(LastName='Sample Last NAme', boolean__c=True);
       insert con;
		
		Task tsk = New Task();
		tsk.WhoId = con.Id;
		tsk.Subject = 'Mass Email';
		tsk.Status = 'In Progress';
		tsk.Priority = 'Low';
		insert tsk;
    }
}

Please mark as best answer if helped.

Regards,
Ramakant​ 

All Answers

RKSalesforceRKSalesforce
Hi Sumit,

Hope Below Test Class will work:
@isTest 
private class SampleTestClass {
    static testMethod void validateContactsAndTasks() {
       Contact con = new Contact(LastName='Sample Last NAme', boolean__c=True);
       insert con;
		
		Task tsk = New Task();
		tsk.WhoId = con.Id;
		tsk.Subject = 'Mass Email';
		tsk.Status = 'In Progress';
		tsk.Priority = 'Low';
		insert tsk;
    }
}

Please mark as best answer if helped.

Regards,
Ramakant​ 
This was selected as the best answer
RahulRahul
Thank you  so much for help Ramakant :)