LinkedIn

Salesforce Screen Flow - Roll Back Behavior

 Similar to Apex Roll Back, as part of Winter 22, Salesforce has introduced Flow Roll Back feature also. Let us see the transaction behavior when using roll Back along with Screen Flow.


1. Feature Details

As of now Roll Back feature is available only for Screen Flows. 

All pending operations in the current transaction will be rolled back on adding Roll Back element to a fault connector.

This is useful when we have a series of DML operations happening in a single transaction and ScreenFlow will try to combine all those into a single transaction

2. Use Case - Single Input Screen - Multiple DML 

I would like to develop a screen where you can create both Account and Contact together on a single screen. The flow looks like below:




The input screen looks like below:



And once you enter details in all fields and click on next, Below operations will be happening:


Below is the Transaction Behavior




3. Add failure to Contact Save

Now let us add a validation rule on Contact to make the email field mandatory:



Now try to submit the screen without entering the Email field. 


The behavior is as mentioned below:


4. How to Add Roll Back Behavior

Instead of the above flow, if the Contact creation got failed, we would like to rollback Account creation also. Let us see how this can be achieved by replacing the fault connector action with Roll Back behavior instead of a screen message.


Now try to create new data:



5. Transaction Behavior after adding Roll Back


Also in the debug you can notice that both account and contact save happening in the same transaction, and that is the reason Roll Back is a success here.


6. Use Case Modified -Multiple Input Screen  - Multiple DML

Now let us modify the screen flow to use 2 separate screens for entering Account and Contact Data:


Let us try to create new Account and Contact now without entering an email :


7. Transaction Behavior


8. Why Roll Back didn't happen?

If you check the debug log you can see that Account and Contact creation happened as 2 different transactions and Roll Back will happen to DML operations occurring in the same transaction

Account Debug:


Contact Debug:


This is because based on this documentation, a flow transaction is end when a screen element, local action and pause element is executed.

9. Summary

Based on the above analysis, Roll Back will be happening for DMLs which are part of the same transaction only. Even if we have multiple DMLs as part of the same screen flow, but they end up in different transactions, Roll Back will not be successful.

Comments

  1. I wonder about how to see debug log about flow process. Could you let me know about it?

    ReplyDelete
  2. How do I go about when I reject an approval and want to go back to the previous picklist in my case. What are the steps in details if you don't mind me asking? Very great website and please keep the information coming.

    ReplyDelete
  3. So I have 1 approval process and 1 flow that calls that approval process. Once the flow triggers, it emails the approval and the approval can email approve or reject. It works well when approves but when I reject I want it to go to the original picklist since it didn't get approve. My picklist are A, B, C, D. Approval is needed for A, and B. If A is rejected it should stay at A

    ReplyDelete
    Replies
    1. Hi Stel,

      I think you need to have custom logic around this, since rollback behavior is supported only for screenflows. So you might need to store the previous picklist value in some other field, and once rejected, retrieve this and update back the picklist.

      Delete
    2. Hi Meera, could you point me to some examples for references? Much appreciated!

      Delete
  4. Hi Meera, I found this reference https://www.salesforcebolt.com/2020/10/get-prior-value-of-formula-field-in.html and it's using workflow but can it be done with flow to store the value?

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. Site Reliability Engineering Training
    SRE Training in Hyderabad
    Site Reliability Engineering Training in Hyderabad
    Site Reliability Engineering Online Training
    Site Reliability Engineering Training Institute in Hyderabad
    SRE Training Course in Hyderabad
    SRE Online Training in Hyderabad

    ReplyDelete

Post a Comment

Popular posts from this blog

Subscribing to Salesforce Platform Events using External Java Client - CometD

Send Data from Salesforce to Data Cloud using Ingestion API and Flow

How to develop reusable Invocable Apex methods for Flows