2

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?

  • The formula looks OK to me. Could you include the invocable class as well? – Hengky Ilawan Dec 17 '19 at 22:31
  • @HengkyIlawan Added the invocable class. – Austin Evans Dec 17 '19 at 22:37
  • 1
    The error is the CPU time limit. The other message is an artifact of how debug logs present collections. – David Reed Dec 17 '19 at 22:54
  • I think you can use Developer Console (switch to Analysis perspective) to identify which execution unit in your class that has consumed too much of CPU limit. – Hengky Ilawan Dec 17 '19 at 23:04
  • I am surprised to see the CPU time limit exception. Is it normal to get this exception with updating around 100 records (which in turn invokes Invocable class)? @DavidReed – Austin Evans Dec 17 '19 at 23:05
3

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.

| improve this answer | |
  • Sounds good David, I will definitely try it. I will keep you posted. – Austin Evans Dec 17 '19 at 23:13
  • Hi David, after deactivating the Process, my data load completed with ~4000 out of 10000 CPU Time limit. But, when I activate the process, I am getting ~19000 out of 10000 time limit. I am still unable to figure out the issue here? I have opened a case with Salesforce support though, but still, if you have any insights, that would be great. – Austin Evans Dec 19 '19 at 15:42
  • What happens where your code says //Do something? – David Reed Dec 19 '19 at 18:14
  • I have enqueueJob that does a callout. But the execution is not even going that far. I have few debug statements just above that if() statement which are not even getting triggered. Also, I can see the CPU time out error when the execution is in the for() loop of getMetadataRecs method. – Austin Evans Dec 19 '19 at 19:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.