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
MS123456MS123456 

Can You Any One Pls Tell I am Writing Test Is it bulkify test cls

Hi Team Pls Help me is bulkify Or not Test Class........
@isTest 
public class eventTriggerContactTest 
{
    static testMethod void testMostRecentUpdation() 
    {
        Contact objContact = new Contact();
        objContact.LastName = 'TestCon';
        objContact.FirstName = 'TestCon';
        insert objContact;
        
        Event objEvent = new Event();
        
        for(Integer i=0;i<=200; i++)
        {
        objEvent.Type = 'Consult';
        objEvent.Description = 'Test Desc'; 
        objEvent.whoId = objContact.Id;
        objEvent.Meeting_Type__c='Phone';
        objEvent.Event_Status__c='Completed';
        objEvent.Phone_Call_Type__c='Inbound';
        objEvent.StartDateTime = System.today();
        objEvent.EndDateTime = System.today();
        objEvent.Subject  = 'Test Event';
        }
        
        
        insert objEvent;
        
        System.assertEquals(objEvent.Id, [SELECT Most_Recent_Event_Id__c FROM Contact WHERE Id =: objContact.Id].Most_Recent_Event_Id__c);
        
        Event objEvent2 = new Event();
        
        for(Integer i=0;i<=200;i++)
        {
        objEvent2.Type = 'Consult';
        objEvent2.Description = 'Test Desc';
        objEvent2.Meeting_Type__c='Phone';
        objEvent2.Event_Status__c='Completed';
        objEvent2.Phone_Call_Type__c='Inbound';
        objEvent2.whoId = objContact.Id;
        objEvent2.StartDateTime = System.today();
        objEvent2.EndDateTime = System.today();
        objEvent2.Subject  = 'Test Event';
        }
      
        insert objEvent2;
        System.assertEquals(objEvent2.Id, [SELECT Most_Recent_Event_Id__c FROM Contact WHERE Id =: objContact.Id].Most_Recent_Event_Id__c);
        
        update objEvent;
    }
    
}
Banwari kevat1Banwari kevat1
Hi Mayur,
     This is not bulkified. You are trying to insert 200 Event records but your code willl not work as you expexted because you are creating only one reference of Event object and and assigning field value in loop will overide to previos loop iterartion. You can follow below code snippet to insert more than one record.
 
List<Event> objEventList = new List<Event>();
        for(Integer i=0;i<=200; i++)
        {
        Event objEvent = new Event();
        objEvent.Type = 'Consult';
        objEvent.Description = 'Test Desc'+i; 
        objEvent.whoId = objContact.Id;
        objEvent.Meeting_Type__c='Phone';
        objEvent.Event_Status__c='Completed';
        objEvent.Phone_Call_Type__c='Inbound';
        objEvent.StartDateTime = System.today();
        objEvent.EndDateTime = System.today();
        objEvent.Subject  = 'Test Event'+i;
        objEventList.add(objEvent);
        }
        
        
        insert objEventList;

Thanks
Banwari
Skype: bkevat92​
Amit Chaudhary 8Amit Chaudhary 8
You can try like below
@isTest 
public class eventTriggerContactTest 
{
    static testMethod void testMostRecentUpdation() 
    {
        Contact objContact = new Contact();
        objContact.LastName = 'TestCon';
        objContact.FirstName = 'TestCon';
        insert objContact;
        
        List<Event> ListobjEvent = new List<Event>();
        Event objEvent;
        for(Integer i=0;i<=200; i++)
        {
			objEvent = new Event();
			objEvent.Type = 'Consult';
			objEvent.Description = 'Test Desc'; 
			objEvent.whoId = objContact.Id;
			objEvent.Meeting_Type__c='Phone';
			objEvent.Event_Status__c='Completed';
			objEvent.Phone_Call_Type__c='Inbound';
			objEvent.StartDateTime = System.today();
			objEvent.EndDateTime = System.today();
			objEvent.Subject  = 'Test Event';
			ListobjEvent.add(objEvent);
        }
        insert ListobjEvent;
        
        System.assertEquals(objEvent.Id, [SELECT Most_Recent_Event_Id__c FROM Contact WHERE Id =: objContact.Id].Most_Recent_Event_Id__c);
        
        Event objEvent2 = new Event();
        
		objEvent2.Type = 'Consult';
		objEvent2.Description = 'Test Desc';
		objEvent2.Meeting_Type__c='Phone';
		objEvent2.Event_Status__c='Completed';
		objEvent2.Phone_Call_Type__c='Inbound';
		objEvent2.whoId = objContact.Id;
		objEvent2.StartDateTime = System.today();
		objEvent2.EndDateTime = System.today();
		objEvent2.Subject  = 'Test Event';
        insert objEvent2;
        System.assertEquals(objEvent2.Id, [SELECT Most_Recent_Event_Id__c FROM Contact WHERE Id =: objContact.Id].Most_Recent_Event_Id__c);
        
        update objEvent;
    }
    
}

Let us know if this will help you