Using the mass mutate step: insert

Creating multiple records 1-by-1 can take up some time, with the bulk insert you can create them all in one go.

After reading this article you'll know:

  • What the mass mutate step is

  • Why use the mass mutate step for inserting records

  • How to use the mass mutate step in your application

Mass mutate step can be found in the Block Store and is used to mass mutate data, this can be inserting-, upserting-, and deleting many records. To find the step go to the block store and search for 'mass', the Mass mutate step should pop up.

Click on View details followed by Install block to install the block to the appropriate organization and application.

Once installed we can use the step in our application.

Prerequisites

The following data models are pre-created to showcase what the step is about:

The above models form a questionnaire template, within this template we can then generate questionnaires using the mass mutate step.

Basically what we're doing in this use case is creating a questionnaire template with questions, then based on the number of employees in your employee model the template will be created a number of times with associated questions.

In this example, there's a handful of employees, but imagine if you have a huge enterprise and you need to create questionnaires for 20,000 employees. You can imagine that'd take quite some time by simply looping through that collection and then create the questionnaires plus the associated questions. A questionnaire that has 25 questions would result in half a million new records being created.

Power of mass mutate

The mass mutate makes the example above a lot faster, this step 'intercepts' the call to the database. So instead of doing a create half a million times, it'll save them up and then insert them in one go.

How does this work you might ask? This is the action that creates questionnaires based on the questionnaire template:

In the Start step input variables are created that require the 'id' of a questionnaire template.

We then create a normal variable that retrieves the object of the questionnaire template using a filter based on 'id' like so:

And another variable to get the number of employees:

The first step in the action is the Mass mutate step. This step has no configuration required, it will actually work straight out of the box. Everything that happens in the step will be intercepted and inserted (or updated and/or deleted based what you want) in one go. Making the process of mass inserting a lot faster!

The next step is to Loop through the employee collection like this:

After that, we can create a questionnaire for each employee by adding a Create record step in the loop:

Still, in this Loop, we'll have to add another Loop that'll create a number of questions based on the question template model.

Then we create these questions every iteration by adding a second create step within this Loop:

And that's all.

If we execute this action and we provide an 'id' of the questionnaire template we'll create questionnaires for all our employees. In this use case, I only have 8 employees and 3 questions in my template but when I run the action via the playground we can see that they're being created with the associated questions.

Questionnaire:

Questions: