+ Start a Discussion
sumit sharma 200sumit sharma 200 

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 sumit sharma 200
RamakantRamakant
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

RamakantRamakant
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
sumit sharma 200sumit sharma 200
Thank you  so much for help Ramakant :)