I am trying to learn more about Process Builder along with Visual Workflow.

Currently, I have some apex code that operates in bulk that will query a set of accounts in a trigger to see if a text field City__c is NOT null. If it's not null it will store the id of the account and City__c. It will then query a custom object called Baseball Team and return the id of the Baseball Team based on the name of the city. Once done it will update the account lookup field with the id of baseball team.

How can I move this to Visual Workflow and Process Builder. If certain fields are checked I want this to affect all records. e.g. Dataloading 2000 files.

Currently I have a Custom Button passing in an account id and the city to the flow but this doesn't scale. I want to operate on more than 1 record at a time. Thank you in advance.

2 Answers 2


Currently, Flow can do this without any Apex, under certain conditions. You can run bulkified queries INSIDE flow, but you cannot CALL a flow in a bulkified way.

Therefore, the key is to write all of the bulkification inside your flow. Flow has special elements called Fast Lookup and Fast Update (also Fast Create and Fast Delete for those purposes) which are inherently bulkified. By using Fast Lookup to create your map (in Flow, the equivalent is an sObject Collection Variable), you can use a Loop and some Assignment elements to either alter your map or move its data to another one, and then use a Fast Update to push the updates on all the mapped records in a bulkified fashion. Make sure you follow good code practices, e.g. not putting any lookups inside a loop, etc.

If you can find a way to call your Flow once and let it do all the searching/mapping using the above-mentioned tools, you should be in the clear. If you get stuck on any particulars, feel free to let me know.

  • Thanks -- Am I correct to assume that this flow will cause an error if I try to update these records using the api?
    – DNE
    May 25, 2015 at 18:39
  • 1
    I believe so, if your API calls each record individually, and your flow is set to run on the update of the record. I would recommend instead that your flow runs once after the fact, gathering up all of its info and processing and the end of, or after, your API call. You could create a checkbox that triggers the flow going off, and have that be the last thing that is set by your API call. May 25, 2015 at 18:51

Generally speaking, you need to either use an Apex Plug-in or call an Invokable method to do this. In the Apex Code Developer's Guide, you'll find more on Passing Data to a Flow Using the Process.Plugin Interface. Per the example shown in this link, you can Invoke Apex Code from a Flow. There's also an example at this link of a Sample Process.Plugin Implementation for Lead Conversion.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .