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
[Lindsey Kiken][Lindsey Kiken] 

Help with More Efficiently Batching a Standard Case Comment Object Trigger

I have trigger on the standard Case Comment object that performs the following actions:

When a Case Comment is created, it meets our criteria for an internal user, and the First Response fields on the Case Comment's Parent Case are null, stamp the Case Comment's Created By user into the First Response By field on the Case and the Case Comment's Created Date date/time info into the First Response On field on the Case.

The current working code is as follows:
 
trigger FirstResponse on CaseComment (after insert) 
{
    Set<Id> parentIds = new Set<ID>();
    Set<Id> CreatorIds = new Set<ID>();
    Map<ID,Schema.RecordTypeInfo> rt_Map = Case.sObjectType.getDescribe().getRecordTypeInfosById(); 
    List<Case> cases = new List<Case>();
    map<id,case> mapIdTocase = new map<id,case>();
    list<Case> lstCaseTobeUpdate = new list<Case>();
    //Get all the Parent Ids (cases) in the Set
    for(CaseComment cc : Trigger.new)
    {
        parentIds.add(cc.ParentId);
        CreatorIds.add(cc.CreatedByID);
    }
    map<id,user> mapCommentUsr = new map<id,user>([select Id,ProfileId,profile.name FROM User where id IN:CreatorIds]); 
    cases = [Select Id, First_Response_On__c, First_Response_By__c, Internal_vs_External__c, RecordTypeID, Origin, of_Comments__c, Status from Case where Id in :parentIds limit 1];
    for(case objcase : cases)
    {
        mapIdTocase.put(objcase.id,objcase);
    }
    for(CaseComment cc : Trigger.new)
    {
//Fire if the Status is New
        if(
            cc.IsPublished == TRUE && 
            mapIdTocase.get(cc.parentid).First_Response_On__c == null &&
            mapIdTocase.get(cc.parentid).Status == 'New' &&
            rt_map.get(mapIdTocase.get(cc.parentid).recordTypeID).getName().containsIgnoreCase('Support Case') &&
            mapCommentUsr.get(cc.createdbyid).profile.name != 'Customer Community Login User' &&
            mapCommentUsr.get(cc.createdbyid).profile.name != 'Customer Community User' &&
            mapCommentUsr.get(cc.createdbyid).profile.name != 'Elemental Community Login User' &&
            mapCommentUsr.get(cc.createdbyid).profile.name != 'Elemental Community User' &&
            mapCommentUsr.get(cc.createdbyid).profile.name != 'Partner Community User' &&
            cc.createdbyid != '00570000003UrOPAA0'
        ){
                mapIdTocase.get(cc.parentid).First_Response_On__c = system.now();
                mapIdTocase.get(cc.parentid).First_Response_By__c = cc.CreatedById;             
                mapIdTocase.get(cc.parentid).Status = 'Open'; 
                lstCaseTobeUpdate.add(mapIdTocase.get(cc.parentid));
        }

        else if(
            cc.IsPublished == TRUE && 
            mapIdTocase.get(cc.parentid).First_Response_On__c == null &&
            mapIdTocase.get(cc.parentid).Status != 'New' &&
            rt_map.get(mapIdTocase.get(cc.parentid).recordTypeID).getName().containsIgnoreCase('Support Case') &&
            mapCommentUsr.get(cc.createdbyid).profile.name != 'Customer Community Login User' &&
            mapCommentUsr.get(cc.createdbyid).profile.name != 'Customer Community User' &&
            mapCommentUsr.get(cc.createdbyid).profile.name != 'Elemental Community Login User' &&
            mapCommentUsr.get(cc.createdbyid).profile.name != 'Elemental Community User' &&
            mapCommentUsr.get(cc.createdbyid).profile.name != 'Partner Community User' &&
            cc.createdbyid != '00570000003UrOPAA0'
        ){
                mapIdTocase.get(cc.parentid).First_Response_On__c = system.now();
                mapIdTocase.get(cc.parentid).First_Response_By__c = cc.CreatedById;             
                lstCaseTobeUpdate.add(mapIdTocase.get(cc.parentid));
        }
        
            if(lstCaseTobeUpdate != null && lstCaseTobeUpdate.size()>0)
            {
                update lstCaseTobeUpdate;
            }
    }
}

We received a batching error when trying to bulk load case comments, but I unfortunately do not know where to start regarding more efficiently batching this code.

Help is much appreciated!