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
Bharat SBharat S 

Can anyone help me write Test Class for mentioned Apex Class

I am a beginner in Salesforce and Apex. Can anyone help me write TestClass for this Apex Class.

Event Trigger Handler

public class EventTriggerHandler {

    public static String comma = ',';
    
    public static void AfterInsert(Map<id, Event> EventMap)
    {
        try
        {
            String NameTitle ='';
            String Names;
            
            List<EventRelation>EveRelationList=New List<EventRelation>();
            EveRelationList = [SELECT Id, RelationId,EventId FROM EventRelation WHERE EventId In : eventMap.keyset() and RelationId != null];
             system.debug('AfterInsert count_____'+EveRelationList.size());
            Set<Id> WhoIds = New set<Id>();
            for(EventRelation eveRel : EveRelationList){
                WhoIds.add(eveRel.RelationId);
                system.debug('WhoIds after insert_____'+WhoIds);
            }
            List<Contact> ConList = New List<Contact>();
            ConList=[Select Id,Title,FirstName,LastName, Name FROM Contact WHERE Id In : WhoIds and Title != null and Name != null];
            for(Contact c : ConList){
                if(c.Title!= null)
                {
                    NameTitle = NameTitle+c.Name + '(' + c.Title + ')' + comma ;
                }
            }
            Names = NameTitle.removeEnd(comma);
            System.debug('Names'  + Names);
            List<Event> eventList = new List<Event>();
        
            for (Event e : [select id, Title__c from Event where Id in: eventMap.keyset()])
            {
                e.Title__c = Names;
                eventList.add(e);
            }
            update eventList;
        }
        catch(exception e)
        {
             throw e;    
        }
    }
}

Event Trigger

trigger EventTrigger on Event (before insert, before update, after insert) {
    if (Trigger.IsBefore) {
        if (Trigger.isInsert) {
        }
        if (Trigger.isUpdate) {
        }
    }
    if(Trigger.IsAfter)
    {
        if (Trigger.isInsert) {
            EventTriggerHandler.AfterInsert(trigger.newMap);
        }
    }
    
}

 
Edwin VijayEdwin Vijay
In your test class you would create a couple contacts, create an event with event relations. That should fire the trigger and the related handler. You can then assert the expected results against your actual result.  This article should give you a fair idea on how to get started with this https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm