You need to sign in to do that
Don't have an account?
Raffus
Not able to cover this line of code, enrollmentsId are not inserted
This is method
This mine test method
public static void carriersBMLLUpdatecreateCaseComments(List<Enrollment__c> newList,Map<Id,Enrollment__c> oldMap) { Set<Id> enrollmentIds = new Set<Id>(); Map<Id, Enrollment__c> newMap = new Map<Id, Enrollment__c>(newList); for(Enrollment__c enrollment: newList) { //on update if(oldMap!=null) { if(enrollment.Enrollment_Method__c == Label.AFocus_ThirdParty_PickVal){ if(enrollment.Carriers_BMLL_will_not_be_the_GA__c !=null && enrollment.Carriers_BMLL_will_not_be_the_GA__c != oldMap.get(enrollment.Id).Carriers_BMLL_will_not_be_the_GA__c) { enrollmentIds.add(enrollment.Id); } } } //on insert else if(oldMap==null){ if(enrollment.Enrollment_Method__c == Label.AFocus_ThirdParty_PickVal){ if(enrollment.Carriers_BMLL_will_not_be_the_GA__c == null || enrollment.Carriers_BMLL_will_not_be_the_GA__c =='') { enrollmentIds.add(enrollment.Id); } } } } System.debug('enrollmentIds are'+enrollmentIds); List<Case> enrollmentCases = new List<Case>(); List<CaseComment> CaseCommentsList = new List<CaseComment>(); if(enrollmentIds.size()>0) { enrollmentCases = [Select Id,Enrollment__c,Enrollment__r.Carriers_BMLL_will_not_be_the_GA__c,Enrollment__r.Enrollment_Method__c from Case where Enrollment__c IN :enrollmentIds AND Recordtype.Name = :Label.AFocus_New_Business_Case]; if(enrollmentCases.size()>0) { for(Case enrollemtCase:enrollmentCases) { CaseComment caseComment = new CaseComment(); caseComment.ParentId = enrollemtCase.Id; caseComment.IsPublished = false; caseComment.CommentBody = 'ATTN:New Business Team Carriers BMLL will not be the GA:['+ enrollemtCase.Enrollment__r.Carriers_BMLL_will_not_be_the_GA__c +'] When Services are created for this Carriers add $0 in SCA PEPM field on each Service'; CaseCommentsList.add(caseComment); } } } System.debug('CaseCommentsList is :' + CaseCommentsList); try{ if(!CaseCommentsList.isEmpty()){ insert CaseCommentsList; } } catch(Exception ex){ // ExceptionHandlerController.logErrorsInboundAPI('Sync BenAdminBuildCase Notes with Enrollment Notes','AFocus_EnrollmentTriggerHandler','updatecaseNotesFromEnrollmentNotes',ex.getMessage(),'Case ids to be updated' +caseUpdatedList,'Exception occurred during updating status',UserInfo.getUserId(),'Error'); ExceptionHandlerController.logErrorsInboundAPI('Create Case Comments when Carriers_BMLL_will_not_be_the_GA__c is updated','AFocus_EnrollmentTriggerHandler','carriersBMLLUpdatecreateCaseComments',ex.getMessage(),'Carriers_BMLL_will_not_be_the_GA__c to be updated' +CaseCommentsList,'Exception occurred during updating Carriers_BMLL_will_not_be_the_GA__c',UserInfo.getUserId(),'Error'); } }
This mine test method
@isTest static void carriersBMLLUpdatecreateCaseCommentsTest(){ Set<Id> enrollmentIds = new Set<Id>(); string Id =[SELECT id from RecordType where Name ='Agency'].Id; Account Acc1 = new Account(); Acc1.Name = 'Test Account forth'; Acc1.Email__c='testtest@gmail.com'; Acc1.Source_System__c ='BenefitPoint'; Acc1.Technology_Adoption__c ='Low - Not Open'; Acc1.RecordTypeId = Id; insert Acc1; System.debug('Account info: ' + Acc1); List<Enrollment__c> enlist = new List<Enrollment__c>(); Enrollment__c en1 = new Enrollment__c(); en1.Broker__c= Acc1.id; en1.Status__c='Not Submitted'; en1.Notes__c='Test Notes'; en1.Plan_Selection_Complete__c= true; en1.Street__c = 'eStreet'; en1.city__c = 'New york'; en1.State__c = 'NY'; en1.Zip__c = '48979842'; en1.Effective_Date__c = system.today(); en1.Client_Type_Status__c = 'Group'; en1.EIN__c = '281764'; en1.Phone__c = '(555) 123-4567'; en1.Full_Time_Employees__c = 80; en1.Enrollment_Method__c='Third-party'; en1.Carriers_BMLL_will_not_be_the_GA__c ='test'; insert en1; enlist.add(en1); //insert enlist; System.debug('Enrollment1 info: ' + en1); enrollmentIds.add(en1.Id); Map<Id,Enrollment__c> eListMap = new Map<Id,Enrollment__c>(); eListMap.put(en1.Id,en1); system.debug('elistMap '+ eListMap); Id RTypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Benefit New Business / Renewal').getRecordTypeId(); case caseRec=new case(); caseRec.RecordTypeId = RTypeId; caseRec.Origin='Sales Escalation'; caseRec.SuppliedEmail='test1234@test1234.com'; caseRec.Reason='APS'; caseRec.subject='Installation Problem'; //caseRec.AccountId=accGpRec.id; caseRec.Status = 'New'; caseRec.Approval_Status__c = 'Not Submitted'; //caseRec.NBA_Rep__c = UserInfo.getUserId(); caseRec.Enrollment__c = en1.Id; insert caseRec; System.debug('Case1 info: ' + caseRec); CaseComment comment1 = new CaseComment(); comment1.ParentId = caseRec.Id; comment1.CommentBody = 'Case record 1 comment'; comment1.IsPublished = TRUE; insert comment1; System.debug('Case comment ' + comment1); AFocus_EnrollmentTriggerHandler.carriersBMLLUpdatecreateCaseComments(enlist,eListMap); }
try with below code.
If this helps, Please mark it as best answer.
Thanks!!