+ Start a Discussion
Adelchi PelizzoAdelchi Pelizzo 

Flow Error: The number of results does not match ....

I am getting this error: The number of results does not match the number of interviews that were executed in a single bulk execution request.
Here is the apex class I am using, I want to store list<string> data from a json file into a flow variable:
global class par{

    global static List<string> l = new list<string>();
    
@InvocableMethod(label='Get Map' description='Returns the values of Maps')
    global static List<String> CallMap(){
        HttpRequest req = new HttpRequest();
        req.setEndpoint('https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=AIzaSyBOyIQi54LMykmzSOvCuQ2naVvVQEsEfHw');
        req.setMethod('GET');
        Http http = new Http();
        HTTPResponse res = http.send(req);
        JSONParser parser = JSON.createParser(res.getBody());
        while (parser.nextToken()!= null)
        {
            if ((parser.getCurrentToken() == JSONToken.FIELD_NAME))
            {
                    string fieldName = parser.getText();
                    parser.nextToken();
                if(fieldName == 'place_id')
                {
                    string place = parser.getText();
                    system.debug(place);
                    l.add(place);
                	parser.nextToken();
                }else if(fieldName == 'status')
                	{
                    string status = parser.getText();
                    system.debug(status);
                    l.add(status);
                    }
        	}
    	}
        return l;
    }
}



 

 
NagendraNagendra (Salesforce Developers) 
Hi Adeichi,

I ran into a similar issue. Basically, the size (and possibly type?) of the return value needs to match the input value. I resolved the issue by returning void. Because flows run asynchronously, it seems like a best practice to always return void; then in unit tests, query for any expected results after the action has executed. 

Please mark this post as solved if it helps.

Best Regards,
Nagendra.P
Adelchi PelizzoAdelchi Pelizzo
Thank you for copy and paste: http://salesforce.stackexchange.com/questions/116249/what-does-this-flow-error-mean-the-number-of-results-does-not-match-the-number
Team  CodEngine.inTeam CodEngine.in
I got the same issue. Remember that size of the list you pass to the Apex code should be similar to the size of the list you return to the flow  
Jason Kuzmak 12Jason Kuzmak 12

Why though? I'm trying to get multiple records that all return as results queried from a single value. The only reason I'm passing my invocable method a list at all is because I have to. 

While trying to build a flow that grabs and builds the correct list of checklist questions for a particular machine model that's being serviced, my query string is:

'Select Id, Checkbox_Options__c, Checklist_Template_Section__c, Objective__c, Required__c, Sort_Order__c From Checklist_Template_Item__c Where Applies_To__c Includes(:searchModel)'   

SearchModel can only be a single model of machine that a field tech is servicing.

Trent Foor 5Trent Foor 5
We ran into the same issue, but were able to rectify it without having to return void. As others have stated, the size of the output collection needs to match the size of the inptut collection.
Our specific issue was related to Contacts. We were having issues where Contact records were being created at the same time. Because of this, an invocable method we were utilizing was being called once, but had multiple elements. Our method was processing the list but we were only returning 1 element. This caused the above error. Our solution for this was looping over the intial list. If the size of the collection is above 1, we are returning a result for each element.