5

I'm currently using processes to update records. The ills describing of using the process builder are known to me, but I need more information on how 'Update Record actions' in a process are bulkified.

The official Salesforce documentation says that "Each Update Records action uses one SOQL query and one DML statement." Is this per record or per DML transaction that fired the process?

Example: If inserted 10 cases that match the criteria for a process with an Update Action, would I expect to see 1, 10, or some other number of soql queries & DML operations consumed?

  • Thanks for this question. I always love optimization/performance questions, so it gave me a moment to play with it. – sfdcfox Mar 31 '18 at 0:58
9

It's one DML and SOQL per 200 records or a single DML "chunk."

To illustrate this, consider the following code:

contact[] c = [select id from contact limit 5];
id accountid = [select id from account where ispersonaccount = false limit 1].id;
c.add(new contact(lastname='test1', accountid=accountid));
c.add(new contact(lastname='test2', accountid=accountid));
c.add(new contact(lastname='test3', accountid=accountid));
c.add(new contact(lastname='test4', accountid=accountid));
c.add(new contact(lastname='test5', accountid=accountid));
upsert c contact.id;

Here, we have two upsert chunks; we're updating five records and inserting five more, all in one DML statement. I've purposefully turned off everything else in my org except a single process builder that updates the account with the contact's name. The logs end up looking like this:

  Number of SOQL queries: 4 out of 100
  Number of query rows: 11 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 3 out of 150
  Number of DML rows: 20 out of 10000

The code I wrote uses the following limits:

  Number of SOQL queries: 2 out of 100
  Number of query rows: 6 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 1 out of 150
  Number of DML rows: 10 out of 10000

Activating the process added 2 more queries, 5 more query rows, 2 more DML statements, and 10 more DML rows. My DML statement is an upsert, which it decided were five inserts and five updates, so two "chunks." Apparently, only 5 records were queried, because we went from 6 to 11 rows queried, 2 additional queries were issued, 2 DML statements resulted from the two chunks, and 10 more rows were added (one for each original row in DML statement).

As you can therefore conclude, it is 1 query and 1 DML statement per chunked transaction. Keep in mind that you're also charged for query rows and DML rows accordingly.

  • see also a somewhat related study on PB bulkification – cropredy Apr 1 '18 at 4:19
  • Thanks for the breakdown, this is what I was looking for! To make more assertions based on this understanding of "chunked transactions": it appears SOQL queries are not consumed merely by entering the process itself - only for actions taken by the process (in this case, an 'Update Action'). If then a process were to branch and take multiple actions, would thact factor in the equation? EI: 1 query and 1 dml per chunk * number of actions? Thanks again! – NickNickelodeon Apr 1 '18 at 18:27
  • @NickNickelodeon yes, I'm going to edit this answer based on blog link above, but each action taken is one DML and query. – sfdcfox Apr 1 '18 at 19:19
  • 1
    @sfdcfox I was also playing around with this. What I noticed is that if I do one Update Records action on 199 records, it uses 1 SOQL and 1 DML, but 200 records uses 1 SOQL and 2 DML (?), and 201 records uses 2 SOQL and 2 DML. Any idea where that anomaly comes from at the 200 records treshold? Same situation at 400-600-... – Robin De Bondt Feb 21 at 15:30
  • 1
    @sfdcfox Question posted: salesforce.stackexchange.com/questions/251332/… – Robin De Bondt Feb 22 at 9:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.