You need to sign in to do that
Don't have an account?
Bablu Kumar Pandit
How to Cover Sobject Type(Contact) In test class
My Handler Class
My test Class
public class EventTriggerHandler { public static void addSubject(List<Event> lstevent){ Set<Id> setOfConId = new Set<Id>(); Set<Id> setOfEventid = New Set<Id>(); List<Event>lstUpadteEvent = new List<Event>(); Map<Id,Contact> MapOfIdToCon = New Map<id,contact>(); for(Event objevent : lstevent){ if(objevent.WhoId != null && objevent.WhoId.getSObjectType().getDescribe().getName() == 'Contact' && objevent.Subject == null && (objevent.Type__c == 'Candidate Meeting (Internal Interview)' || objevent.Type__c == 'Candidate Meeting (Interview Debrief)' || objevent.Type__c == ' Candidate Meeting (Other)' || objevent.Type__c == 'Client Interview (Direct Hire)' || objevent.type__c == 'Client Meeting (Intake)' || objevent.type__c == 'Client Meeting (Interview Debrief)' || objevent.type__c == 'Client Meeting (Other)' || objevent.type__c == 'Client Meeting (PEM)' || objevent.type__c == 'Client Meeting (Prospecting)' || objevent.type__c == 'Internal Meeting' || objevent.type__c == 'Networking Event' || objevent.type__c == 'Partner/Referral Meeting' || objevent.type__c == 'Vendor Meeting' || objevent.type__c == 'Vendor Prospect Meeting')){ setOfConId.add(objevent.WhoId); setOfEventid.add(objevent.Id); } } System.debug('<---setOfEventid--->'+setOfEventid); System.debug('<---setOfConId---->'+setOfConId); for(Contact objConatct : [Select Id,Name,Current_Title__c,Current_Company__c,Account.Name from Contact where Id IN:setOfConId]){ if(objConatct.Name != null || objConatct.Current_Title__c != null || objConatct.Current_Company__c != null || objConatct.Account.Name != null){ MapOfIdToCon.put(objConatct.id, objConatct); } } System.debug('<---MapOfIdToCon--->'+MapOfIdToCon); for(Event objevent : [Select Id,WhoId,Owner.Name,Subject,Type__c from Event where Id IN:setOfEventid]){ if(MapOfIdToCon.containsKey(objevent.WhoId) && (objevent.Type__c == 'Candidate Meeting (Internal Interview)' || objevent.Type__c == 'Candidate Meeting (Interview Debrief)' || objevent.Type__c == 'Candidate Meeting (Other)')){ objevent.Subject = (MapOfIdToCon.get(objevent.WhoId).Name == null ? ' ' : MapOfIdToCon.get(objevent.WhoId).Name)+','+ +(MapOfIdToCon.get(objevent.whoId).Current_Title__c == null ? ' ' : MapOfIdToCon.get(objevent.whoId).Current_Title__c)+','+' '+(MapOfIdToCon.get(objevent.WhoId).Current_Company__c == null ? ' ' : (MapOfIdToCon.get(objevent.WhoId).Current_Company__c))+' '+'&'+' '+(objevent.Owner.Name == null ? ' ' :objevent.Owner.Name)+','+' '+(objevent.Type__c == null ? ' ' :objevent.Type__c); System.debug('<---subject-->'+objevent.Subject); lstUpadteEvent.add(objevent); } else if(MapOfIdToCon.containsKey(objevent.WhoId) && (objevent.Type__c == 'Client Interview (Direct Hire)' || objevent.type__c == 'Client Meeting (Intake)' || objevent.type__c == 'Client Meeting (Interview Debrief)' || objevent.type__c == 'Client Meeting (Other)' || objevent.type__c == 'Client Meeting (PEM)' || objevent.type__c == 'Client Meeting (Prospecting)' || objevent.type__c == 'Internal Meeting' || objevent.type__c == 'Networking Event' || objevent.type__c == 'Partner/Referral Meeting' || objevent.type__c == 'Vendor Meeting' || objevent.type__c == 'Vendor Prospect Meeting')){ objevent.Subject = objevent.Subject = (MapOfIdToCon.get(objevent.WhoId).Name == null ? ' ' : MapOfIdToCon.get(objevent.WhoId).Name)+','+ +(MapOfIdToCon.get(objevent.whoId).Current_Title__c == null ? ' ' : MapOfIdToCon.get(objevent.whoId).Current_Title__c)+','+' '+(MapOfIdToCon.get(objevent.WhoId).Account.Name == null ? ' ' : (MapOfIdToCon.get(objevent.WhoId).Account.Name))+' '+'&'+' '+(objevent.Owner.Name == null ? ' ' :objevent.Owner.Name)+','+' '+(objevent.Type__c == null ? ' ' :objevent.Type__c); System.debug('<---subject-->'+objevent.Subject); lstUpadteEvent.add(objevent); } } //Event Before update System.debug('<--Before lstUpadteEvent--->'+lstUpadteEvent); if(lstUpadteEvent.size() > 0){ update lstUpadteEvent; } //Event After Update System.debug('<---After lstUpadteEvent---->'+lstUpadteEvent); } }
My test Class
@isTest public class EventTriggerhandlerTest { Static testmethod void Method1(){ //Insertion of Account Account objacc = New Account(); objacc.Name = 'test'; objacc.Company_Allocation__c = 'New'; objacc.Type__c = 'Client'; objacc.Market__c = 'Boston'; objacc.Industry__c = 'agriculture'; objacc.Physical_City__c = 'Test'; objacc.Physical_State_Province__c = 'Test'; // Account DML insert objacc; //Insertion of contact Contact objContact = new Contact(); objContact.AccountId = objacc.Id; objContact.LastName = 'Testing Trigger 1'; objContact.Contact_Type__c = 'Not DM'; objContact.Contact_Allocation__c = 'New'; objContact.Title = 'Test 1'; objContact.Linked_In_URL__c = '@#$$'; objContact.Functional_Area__c = 'Accounting'; objContact.Title_Level__c = 'Accounting Director'; objContact.Database_Sourced__c = 'Rahul Merani'; objContact.Current_Title__c = 'Test'; objContact.Current_Company__c = 'Test Comp'; //Contact DMl Insert objContact; //Insertion of event Event objevent = New Event(); objevent.StartDateTime = System.today(); objEvent.EndDateTime = System.today(); objEvent.WhoId = objevent.Id; objEvent.Type__c = 'Candidate Meeting (Internal Interview)'; insert objevent; } }
Anudeep (Salesforce Developers)
Can you highlight the code that is not covered?