[SalesForce] Invocable class error: List of size 127 too large to display

I have an Invocable class with the entry condition within Process Builder's process:

OR(

  AND(
     ISNEW(),
     OR(
            ISPICKVAL([Case].Origin , "Website"),
            ISPICKVAL([Case].Origin , "Email") 
       )
  ),

  AND( 
     NOT(ISNEW()),
     ISCHANGED([Case].OwnerId)
   )
)

This process works well in differentiating on-creation and on-updating conditions. I have tested by updating a Case record, and it worked.

But, when I update using Data Loader (more than 100 records), my all records are failing to get update. I get this log:

Error message:

We can't save this record because the “Invocable Case process” process
failed. Give your Salesforce admin these details. This interview has
been terminated as another interview in the same bulk execution
request failed with the following error: An unhandled fault has
occurred in this flow

An unhandled fault has occurred while
processing the flow. Please contact your system administrator for
more information. Error ID: 494473561-73646 (291349296)

Here is my debug log:

14:40:13.215 (63215830093)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:512
14:40:13.215 (63215841534)|VARIABLE_SCOPE_BEGIN|[25]|caseIds|List|true|false
14:40:13.215 (63215900021)|VARIABLE_ASSIGNMENT|[25]|caseIds|"List of size 127 too large to display"|0x3fe5e884

…..

14:40:13.215 (63227457037)|EXCEPTION_THROWN|[76]|System.LimitException: Apex CPU time limit exceeded
14:40:13.215 (63227549429)|FATAL_ERROR|System.LimitException: Apex CPU time limit exceeded

Invocable Method:

@InvocableMethod
public static void myInvocableMethod(List<Id> caseIds){
    Map<Id, Group> queueMap = getMetadataRecs();
    Set<Id> matchedCaseIds = new Set<Id>();
    for(Case caseRec: [Select Id, OwnerId From Case Where Id IN : caseIds]){
        if(queueMap.containsKey(caseRec.OwnerId)){
            matchedCaseIds.add(caseRec.Id);
        }
    }

    if(!matchedCaseIds.isEmpty()){
        //Do something
    }

}


public static Map<Id, Group> getMetadataRecs(){
    List<String> nameList = new List<String>();
    Map<Id, Group> tempMap = new Map<Id, Group>();
    List<QueueList__mdt> metaDataRecs = [Select Name__c From QueueList__mdt];

    if(!metaDataRecs.isEmpty()){
        for(QueueList__mdt rec : metaDataRecs){
            nameList.add(rec.Name__c);
        }

        if(!nameList.isEmpty()){
            tempMap = new Map<Id, Group>([Select Name From Group 
                                           Where Type = 'Queue' And Name = :nameList]);
        }
    } 
    return tempMap;
}

My understanding:

As I am sending more than 100 records at once, Process is invoking my Invocable class with List of 100 Ids. But, when the execution flow enters the class, I am getting this error: List of size 127 too large to display and kicking me out.

How to get over this error and be able to bulkify the Process to handle more records?

Best Answer

Here's the core error:

63227549429)|FATAL_ERROR|System.LimitException: Apex CPU time limit exceeded

The other message is simply an artifact of how debug logs show collection values.

I don't think this code is particularly to blame, not by itself at least - unless your "do something" region includes nastily time-complex processing, DML in a loop, or something like that. I'm assuming no because the rest of what you're showing us seems to be bulkified.

Rather, I think this code is the straw that breaks the proverbial camel's back. The transaction as a whole is consuming too much CPU time, but it's not clear that this is the culprit.

The first things I'd do would be to look through the analytics panes in Developer Console to get a better sense of where exactly the CPU time consumption is occurring. That's also a good opportunity to check whether you have some intense save-order recursion taking place that might chew through extra time.