You need to sign in to do that
Don't have an account?
Hermann Ouré
here is the Test class
Test class for field update Trigger
Hello,
I struggle to cover part of my code.
Could someone help?
Thanks
here is my code:
trigger AircallTaskTrigger on Task (after insert, after update) { List<Case> lstCase = new List<Case>(); //Get 'Case Concern' RecordType Name Id caseConcernRecordTypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get(label.Param_Case_Concern).getRecordTypeId(); Map<Id, Case> caseWithAircallTaskMap = new Map<Id, Case>([SELECT Id, First_Aircall_Logged__c FROM Case WHERE RecordTypeId =:caseConcernRecordTypeId]); for(Task t : Trigger.New) { if(t.whatId != null && t.callDisposition!= null && t.callDisposition.containsIgnoreCase('aircall')) { System.debug('#### Aircall debug ' + t.whatId != null && t.callDisposition.containsIgnoreCase('aircall')); Case c = New Case(); if(caseWithAircallTaskMap != null && caseWithAircallTaskMap.containsKey(t.whatId)){ c = caseWithAircallTaskMap.get(t.whatId); if(c.first_Aircall_Logged__c == null){ c.first_Aircall_Logged__c = t.createdDate; if(t.WhatId == c.Id) { lstCase.add(c); } } } } } if (lstCase.size() > 0) { update lstCase; } }
here is the Test class
@isTest public class AircallTaskTriggerTest { @isTest static void testAircallDateUpdate() { Contact con = new Contact (FirstName = 'First Name',LastName = 'Test'); insert con; Case c = new Case(Status = 'New',ContactId = con.Id,Phone_Number__c = '123456789'); insert c; Task t = new Task(Subject = 'Test', WhatId = c.Id, CreatedDate = System.today(), callDisposition = 'aircall'); insert t; c.Id = t.WhatId; c.First_Aircall_Logged__c = null; //System.assertEquals(t.CreatedDate, c.First_Aircall_Logged__c); update c; } }
Insert case record in test class with record type:
Thanks,
Maharajan.C