0

I created a one-time use flow for migration purposes. It looks up all the records to update, and calls a subflow to update each one. The subflow runs 8 or 10 queries and then updates one record.

Unfortunately, the migration flow dies on the 10th record with a Too Many SOQL Queries error. I expected each subflow to execute separately but instead all of the queries of all subflows have been counted towards the total! This is really silly.

It seems that the subflow does not get bulkified. Is there a way to do mass update records from a flow calling a subflow?

Otherwise how can I create a batch process or otherwise call the record update flow for all records? The two options I can imagine now are: 1. call flow from developer console anonymous apex window 2. create a process to call the flow on record update, and force the process to run with data loader or anonymous apex

I tried to run it from an anonymous apex window in developer console but again, my DML fault email tells me "Error Occurred: Too many SOQL queries: 101". FYI this was the code:

String theFlowAPIName ='Meeting_Note_mail_merge_data_field_update_Call_from_Controller';
String q = 'select id from Contact_History__c order by id';
List <Contact_History__c> recs = Database.query(q); // Get list of ids

for (Contact_History__c o : recs) {
  // set flow input parameters
  Map<String, Object> params = new Map<String, Object>();
  params.put('varMeetingNoteId', o.id); 

  // In that component, start the flow to refresh the mail merge data field
  Flow.Interview flow = Flow.Interview.createInterview(theFlowAPIName, params);
  flow.start();
}

Here is a screenshot of the migration flow. The subflow it calls is the same one that is normally called from the controller.

Migration Flow image

1
  • 2
    I recommend you use data loader for this purpose.
    – crmprogdev
    Commented Jul 28, 2019 at 16:02

2 Answers 2

0

I used a flow to migrate a large number of records from financialforceHCM to Sage People. I triggered the flow via a data update with a batch size of 1 which kept me within limits (barely!).

I used subflows to reparent child records including attachments. As long as those are designed to minimize DML you should hopefully be ok. There are some things that flow can't do well and you may run out of runway, but doing this in a batch size of 1 will get you the most mileage.

0

Thank you gorav. I resolved as follows.

  1. Determined that Flow is not appropriate by itself as the migration tool because it will quickly hit the 101 SOQL queries limit. (As posted in my question)

  2. Attempted to call the subflow (same as the one used by my controller on record save) from Developer Console anonymous apex window, as posted above. Proved that it has the exact same problem as above.

  3. The choice is between writing batch apex job or using data loader to force the subflow to execute, so I decided using data loader is faster.

Therefore I did as follows:

Create a hidden field called Migration

Create a migration process in Process Builder for temporary use. When Migration field ISCHANGED it will send the meeting note ID in a flow variable calling the subflow to update the mail merge field.

Use Data Loader to extract id and migration__c fields for all records

Enter some text into all migration__c fields in Excel

Use Data Loader to update all records' migration__c fields, which causes the process to call the subflow. I set the batch size to 5 since I know it works for 9 but not 10.

This solution worked for me and is easier for other admins to understand and maintain as well, so I recommend it.

To me the lack of batchable flows, and transactions within flows, is a major lack of functionality in Salesforce. It does not make sense in any way except that Salesforce perhaps does not want to make it too easy to do useful things that could be abused...

You must log in to answer this question.

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