You need to sign in to do that
Don't have an account?
Adelchi 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:
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; } }
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
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.
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.
1. Issue is mostly caused by Flows and Processes invoking an "Invocable Method".
2. Flows and Processes REQUIRES the same AMOUNT of Results as Requests which where given to the Invocable Method.
3. The Return Type must NOT be the same as the Request type.
4. The Return Type VOID is NOT VALID for Flows and Processes.
5. Workaround for Users which give back LESS Results than Requests: Input Parameter is List<List<WHATEVERYOUWANT>> and Response is also LIST<LIST<WHATEVERYOUWANT>>. The clou is to use always the inner List and add all Requests and Reponses into the inner List. The outer List contains allways the inner List. This results in the same Amount of Requests and Responses (1 List with 1 List)
Last Point Credits go to another User:https://developer.salesforce.com/forums/?id=9062I000000QwROQA0
I had the same error message.
It's not that the size of input and output are the same. It just needs to be a list of lists.
I didn't need to send anything into the method. Using a List<List<>> for the return was necessary.
I then expanded it to send in the group Ids:
I agree with 'David Tissen 7', Kudos to 'Jason Kuzmak 12' for his post https://developer.salesforce.com/forums/?id=9062I000000QwROQA0
I'm Also getting the same error when i tries to find the object name in my code
and uses this apex in one of my flow. Storing the return value in a text variable.
After encountering the issue again in a batch process that was causing an account flow to run, I tried all the above solutions again. Then, almost by accident, I checked the size of the List<List<>> and found mutliple entries when the batch was running. I bulkified my apex class and solved the problem.
So, when a batch process runs, it passes multiple values into the flow. Your flow may only describe one value being returned but the batch will return multiple values.
Two days of head-scratching well spent.
In this case when the flow calls the APEX function what happens is that in input you have a list of values, so you have to manage it.
In my case, I solve it by adding a for each on the input list and doing all the operations for each element of the list.
Dear colleagues,
I am experiencing the same problem with some Apex code already present in our org. A flow will pass one object to the InvocableMethod and everything works fine. However when multiple objects trigger the flow the Apex requests are bulkified and it will return the wrong number of results, it should be just 1 list of lists. I have tried the above list <list> additions but my knowlegde of Apex is not good enough to make all the nessecary adjustments. Can anyone correct this Apex code so it will run when called with multiple inputs?
Thanks in advance, your help is greatly appreciated.
public with sharing class HashAction {
@InvocableMethod(label = 'Get hashed value')
public static list < Result > getHashedValue(list < Request > requests) {
list < Result > results = new list < Result >();
if (requests != null && requests.size() > 0) {
Request request = requests.get(0);
results.add( new Result( getHash( request.getValue() ) ) );
}
return results;
}
public class Request {
@InvocableVariable(label = 'Value to hash' required = true)
public String input;
public String getValue() {
return this.input;
}
}
public class Result {
@InvocableVariable(label = 'Hashed value')
public String hash;
public Result(String hash) {
this.hash = hash;
}
}
public static String getHash(String input) {
if (input == null) {
return null;
}
return EncodingUtil.urlEncode( EncodingUtil.base64Encode( Crypto.generateDigest( 'SHA-256', Blob.valueOf(input) ) ), 'UTF-8' );
// return EncodingUtil.base64Encode( Crypto.generateDigest( 'SHA-256', Blob.valueOf(input) ) );
}
}