Calling Flow from Process Builder and getting error. The Flow has Invocable Apex solely to collect the "bulkified" records that Salesforce gathers, it was my understanding this is how we gathered them to use later.

The Apex does no processing other than to create a List<List<Sobject>> and returns this to the Flow Sobject Collection variable.

The debug logs show 5 transactions started and 1 returned which is essentially what I expect as the 1 should be a collection with the 5 records. Tried adding a 0 min Wait before and after the Invocable Apex which didn't work.

Flow Error - The number of results does not match the number of interviews that were executed

public with sharing class ApexToBulkifyRecords_Confirmation {

    @InvocableMethod(label='Collect Bulkified Records')
    public static List<List<hdone__Confirmation__c>> doAction(Request[] requests) {
        // Process requests
        // Example: Query parents in bulk
        Map<Id, hdone__Confirmation__c> parents = new Map<Id, hdone__Confirmation__c>();

        for(Request request : requests) {
            parents.put(request.recordId, null);

        parents = new Map<Id, hdone__Confirmation__c>([
            SELECT Id
            FROM hdone__Confirmation__c
            WHERE Id IN :parents.keySet()

        // Flows must return List<List> for Sobject Collections
        List<List<hdone__Confirmation__c>> wrapper = new List<List<hdone__Confirmation__c>>();

        List<hdone__Confirmation__c> responseList = new List<hdone__Confirmation__c>();

        System.debug('Size of ResponseList ' + responseList.size());

        System.debug('Return wrapper size ' + wrapper.size());
        return wrapper;

    public with sharing class Request {
        @InvocableVariable(label='Record ID' required=true)
        public Id recordId;

        @InvocableVariable(label='Object API Name' required=false)
        public String objectName;

        @InvocableVariable(label='Parent ID' required=false)
        public Id parentId;

Your Answer

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

Browse other questions tagged or ask your own question.