+ Start a Discussion
Haystack CertifiedHaystack Certified 

Bulkifying visual workflows called by triggers

I have been using code like this for calling Visual Workflows from a trigger.
public static void start(List<Account> TriggerNew) {
        Map<String, Object> myMap = new Map<String, Object>();
        for(Account ac: TriggerNew) {
            myMap.put('txtAccountRecordID', String.valueOf(ac.Id));
            Flow.Interview.Set_Account_Zero_Tax_Rate myFlow = new Flow.Interview.Set_Account_Zero_Tax_Rate(myMap);

The issue is that it is not quite bulkified because the flow is being called individually for each record.  Is there a way to send the entire trigger.new list to the flow?
Now that Visual Workflow supports collections, you should be able to rewrite your Flow to deal with multiple IDs at once, which would allow you to pass multiple records at once.  You'll need to rewrite both your flow and your trigger to use collections rather than single records.