I have a process built with a Process Builder. It fires on contact update/create.
Under certain conditions that process launches a Flow. Flow accepts two Parameters - ContactId and AccountId.
If I do mass update/insert of the contacts and flow is launched through the process, the flow is automatically bulkified disregarding the fact that flow itself accepts a single value of each Id. So, if I upload 100 contacts the flow will query info about the related accounts in one query.
Is there a way to implement the same behavior while launching the Flow from the apex?
I was trying something like the code below but it just launched flow 4 times and even put it into the same apex transaction.
Map<String, String> allParams = new Map<String, String>();
allParams.put('003XXXXXXXXXXX1', '001XXXXXXXXXXX1');
allParams.put('003XXXXXXXXXXX2', '001XXXXXXXXXXX2');
allParams.put('003XXXXXXXXXXX3', '001XXXXXXXXXXX3');
allParams.put('003XXXXXXXXXXX4', '001XXXXXXXXXXX4');
for(String contactId : allParams.keySet()){
Map<String, Object> params = new Map<String, Object>();
params.put('ContactId', contactId);
params.put('AccountId', allParams.get(contactId));
Flow.Interview myFlow = Flow.Interview.createInterview('GreatestFlowOfAllTimes', params));
myFlow.start();
}
I also tried to pass list of parameters instead of single values like:
Map<String, Object> params = new Map<String, Object>();
params.put('ContactId', new List<Id>{003XXXXXXXXXXX1, 003XXXXXXXXXXX2, 003XXXXXXXXXXX3, 003XXXXXXXXXXX4});
params.put('AccountId', new List<Id>{001XXXXXXXXXXX1, 001XXXXXXXXXXX2, 001XXXXXXXXXXX3, 001XXXXXXXXXXX4});
Flow.Interview myFlow = Flow.Interview.createInterview('GreatestFlowOfAllTimes', params));
myFlow.start();
And it doesn't work as well.
Documentation does not provide info about bulkification at all.
Maybe I'm missing something. Please advise.