Salesforce Flow Examples and Top 21 Tips

Salesforce Flow is an automation tool provided by Salesforce which can be used to perform various tasks like, Sending an Email, Posting a chatter, Sending the custom Notifications & etc using clicks instead of code. In this post we will talk about Salesforce Flow Examples and Top 21 Tips for Salesforce Flow. Check out our 15 Salesforce Flow best practices here.

Salesforce Flow Examples and Top 21 Tips

Let see the Top 21 tips for Salesforce flow with Examples. If you new then please check our Salesforce Flow FREE training.

1. Include Entry Criteria

Include Entry Criteria: Always try to include entry criteria in record-triggered flows to restrict only the intended records. We can place decision elements as well after the entry criteria but restricting them at the entry is more efficient.

Lean about One Record Triggered Flow Per Object Per Type.

2. Use formula resources

Use formula resources instead of decision elements for large number of conditions: When dealing with multiple if-else conditions, try to use formula resources to keep the flow simplified. 

For example, you are populating Opportunity description based on the value of amount. So, instead of this:

3. Be careful while using user recordId

Be careful while using user recordId: In flow, the $User.Id returns 15 char case-sensitive Id but any other user lookup fields on record like owner, createdby etc. returns 18 char case-insensitive id. So, while comparing remember convert the 15 digit Id to 18 digit using CASESAFEID() function. 

Here is a screenshot showing the discrepancy:

Tips for Salesforce Flow

4. ISCHANGED operator

Checking record is created scenario when entry criteria contains ISCHANGED operator: When the flow triggering scope is when the record is created and updated and the entry criteria contains ISCHANGED operator, then to check for the create scenario is a bit tricky.

If it is a before save flow, you can include RecordId ISNULL true which denotes the create scenario since the Id gets created only after record is created.

If it is an after save flow, then you can use ISCHANGED on any of the audit fields i.e. CreatedById, CreatedDate, LastModifiedById, LastModifiedDate to detect the created scenario.

5. Do not keep unnecessary resources in flow

Do not keep unnecessary resources in flow: While starting to develop the flow, we tend to create a lot of resources as we try to find out the solution using different approaches. But once the intended solution is achieved, we should clean up any unused resource as part of good practice.

6. Add Proper label and description

Add Proper label and description to each flow elements/resources: While creating an element or resource in flow, ensure proper label and description are provided. This helps in better readability and also makes the work easy for the next developer working on the same flow.

7. Access parent field values using field spanning

Access parent field values using field spanning: In Apex trigger, in order to access parent field value we need to make an SOQL call. But thanks to flow, we can use field spanning to get to the parent field value. No need of additional Get Records.

Salesforce Flow Tips 7 Access parent field values using field spanning

8. Access record type details using field spanning

Access record type details using field spanning: You can also get the record type details using field spanning. No need to use additional Get Records on the RecordType object. But the attempt to access should be done after entry criteria since in entry criteria we can refer to only RecordTypeId, not the other fields of RecordType object

Salesforce Flow Tips 8

9. Try to utilize subflows for repeated operations

Try to utilize subflows for repeated operations: For repeated operations, construct a subflow and reuse the same. For example, we know that the value of multi-select picklist contain semicolon separated values. Now you can create a subflow to parse the selected value and get individual options in a list. This flow can be called from any other flow which parses a multi-select picklist value.

10. Use isEmpty check on collection before Delete operation

Use isEmpty check on collection before Delete operation: Before deleting any collection of records, ensure the list has data. Otherwise you will encounter error similar to what we get in Apex.

11. Consider the execution context of the flow

Consider the execution context of the flow: For auto-launched and screen flow, you get to decide the execution context. There are 3 options:

  1. User or System Context—Depends on How Flow is Launched: In this case, the context is considered from the invoking flow.
  2. System Context with Sharing—Enforces Record-Level Access: In this case, the record level access is applied i.e. the user gets to access the records only which he/she is allowed to access.
  3. System Context Without Sharing—Access All Data: In this case, all the records are accessible during the flow execution.

12. Debug and test a flow properly before activating

Debug and test a flow properly before activating: Before you are activating a flow, ensure you have done enough debugging and testing, not only happy path testing. In case of screen flow, if required run the flow as a particular user and observe the execution. Also, ensure the flow debugging runs in rollback mode so that any database operations are rolled back during debugging.

13. Use dynamic label for screen components

Use dynamic label for screen components: For screen component, you can use dynamic label i.e. the label can be the value of some other flow resource.

Salesforce Flow Example : Use dynamic label for screen components
Salesforce Flow Example : Use dynamic label for screen components

14. Pass recordId as well as record field values from detail page to flow

Pass recordId as well as record field values from detail page to flow: We can pass recordId from the detail page to the flow embedded in the same page. For this, we can declare a text variable in flow named ‘recordId’ and make it Available for input.

Similarly, if we would like to pass entire record to the flow, we can create a record variable and make it Available for input.

15. Keep a check on the flow execution time

Keep a check on the flow execution time: In order to assess the performance of the flow, make use of the $Flow.InterviewStartTime and get the difference from the currentDateTime at the end of the flow to check how long the flow took to execute.

16. Use formula resources for multiplication and division

Use formula resources for multiplication and division: Current there is no multiply and divide operator available for numeric flow resources during assignment operation. So, in order to do multiplication and division, leverage separate formula resources.

17. Use collection filter instead of using Get Records multiple times

Use collection filter instead of using Get Records multiple times: Now flow has come up with collection filter. It is like get the data once and then filter and create subsets as needed.

18. Always test your record-triggered flow in bulk

Always test your record-triggered flow in bulk: Whenever you are creating any record-triggered flow, make sure you are testing it with 5 to 10 records in bulk. This is to ensure the functionality works with multiple records with different scenarios as well.

19. Use $Record_Prior to check for specific value change

Use $Record_Prior to check for specific value change: We have trigger.oldMap and trigger.newMap to check for specific value change in apex trigger. Similarly in record-triggered flow, we have $Record and $Record__Prior which are basically the current and previous state of the record pertaining to the update. So, if we want to check for specific value change, we can check the value of these two variables:

Use $Record_Prior to check for specific value change

20. Make error handling part of your flow

Make error handling part of your flow: Whenever you have any DML, Apex call or any other action included in screen flow, show relevant error message to the user in a separate error screen using fault connector and using the $Flow.FaultMessage variable.

Learn more about Exception handling in flow here.

21. Add bypass logic to skip execution

Add bypass logic to skip execution: Always include bypass logic in record-triggered flows to have the option of skipping the flow logic during data update of large number of records.

Summary

I hope this Salesforce examples and top 21 tips will help you create Salesforce flow with best practices. So it very important to follow the Salesforce best practices to avoid governor limit and design pattern help you to make you configuration as per your company standards.

Abhishek Saha
Abhishek Saha

Salesforce Developer at Accenture | Trailhead Ranger

Articles: 5

6 Comments

  1. Not so sure about tip #8 – I’d double-check user-access to recordtype metadata. In Summer ’21 the release-update (“Enforce Data Access in Flow Merge Fields”) which – unless SF fixed the bug – applied to accessing recordtype field-values via the lookup/span/merge-fields of an object and would fail the flow if the user didn’t have elevated access.

  2. I don’t understand tip #13 – what is this trying to do? How does this help? Flows support localization, so you can override flow labels anyway via the translation workbench.

    Tip #14 needs explanation. If you have the record, this will have the record ID and won’t need to query data assuming the record contains the field(s) you need. If you have the record ID, you can query the data you require in the flow. Why do you state this?

    Tip #21 is dangerous. It says to always provide a way to skip for bulk. This could lead to data becoming inconsistent or other problems. Better to always run the flow and ensure 1. it is highly selective (tip 1) and 2. it is efficient (tips 5, 15, 17, 18).

  3. This statement looks contradictory “Include Entry Criteria” where as in
    https://www.apexhours.com/one-record-triggered-flow-per-object-per-type/
    you mentioned Don’t add the flow entry criteria

    Step 1) Create Record-Triggered Flow
    Create record triggered flow and select the before and after event. Don’t add the flow entry criteria so that it will execute every time when record is created or updated.

    If we are using the Recod Triggered Flow should we use Entry Criteria ?

Leave a Reply

Your email address will not be published. Required fields are marked *