Salesforce Flow Best Practices

While I’m pretty comfortable with Salesforce Flow Best Practices, if you are not, you can safely ask your friendly AI tool for a reminder.

I asked Grok. The one that comes with x.com (the app formerly known as Twitter), and it did a pretty good job.

Why don’t you try your favorite AI tool?

I asked:

What are salesforce flow best practices



The response was pretty comprehensive:


Salesforce Flow is a powerful declarative automation tool, and following best practices ensures your flows are efficient, maintainable, and scalable. Below are some key best practices for designing and implementing Salesforce Flows:

1. Plan Before Building

  • Why: A clear plan prevents rework and ensures the flow meets business requirements.
  • How:
    • Document the process (e.g., using flowcharts or pseudocode).
    • Identify inputs, outputs, decision points, and error conditions before starting.
    • Determine whether Flow is the right tool (e.g., versus Apex for complex logic).

2. Use Descriptive Naming Conventions

  • Why: Clear names make flows easier to understand and maintain.
  • How:
    • Name flows with a consistent pattern (e.g., Object_Process_TriggerType, like Account_Update_Status_Screen).
    • Use meaningful names for variables, elements, and resources (e.g., accountId instead of var1).
    • Add descriptions to the flow and key elements.

3. Minimize Elements and Complexity

  • Why: Simpler flows perform better and are easier to debug.
  • How:
    • Avoid unnecessary loops or nested decisions.
    • Consolidate similar actions (e.g., use one Update Records element instead of multiple).
    • Break complex flows into subflows for modularity.

4. Bulkify Flows

  • Why: Flows triggered by record changes (e.g., Record-Triggered Flows) must handle multiple records efficiently to respect governor limits.
  • How:
    • Use “Get Records” to query all relevant records at once, not per record.
    • Leverage collections (e.g., loop over a list of records) and bulk DML operations (e.g., Update Records with a collection).
  • Example: Instead of updating one contact per account, collect all contacts in a loop and update them in a single action.

5. Handle Errors Gracefully

  • Why: Unhandled errors can confuse users or leave data inconsistent.
  • How:
    • Add Fault Paths for every Get, Create, Update, or Delete element to handle failures.
    • Use Screen elements or custom error messages to inform users (for Screen Flows).
    • Log errors (e.g., to a custom object) for debugging.
  • Example: If a “Create Records” element fails, route to a fault path displaying “Unable to create record. Contact your admin.”

6. Optimize Queries (Get Records)

  • Why: Excessive or inefficient queries can hit governor limits (e.g., 100 SOQL queries per transaction).
  • How:
    • Use specific filters to limit returned records (e.g., WHERE Active__c = true).
    • Avoid querying inside loops; fetch data once and store it in a collection.
    • Use “Limit” if only a few records are needed.

7. Leverage Subflows

  • Why: Reusable subflows reduce redundancy and simplify maintenance.
  • How:
    • Create subflows for common tasks (e.g., sending emails, updating related records).
    • Pass variables between the main flow and subflow using input/output variables.
  • Example: A subflow to notify users can be reused across multiple processes.

8. Avoid Hardcoding

  • Why: Hardcoded values make flows inflexible and hard to update.
  • How:
    • Use Custom Labels, Custom Settings, or Custom Metadata for configurable values (e.g., status picklists, email templates).
    • Store IDs or constants in variables or resources instead of embedding them in elements.

9. Test Thoroughly

  • Why: Untested flows can lead to unexpected behavior in production.
  • How:
    • Test all paths (success, failure, edge cases) using the Debug tool in Flow Builder.
    • Simulate bulk scenarios (e.g., 200 records for record-triggered flows).
    • Use test data with realistic scenarios (e.g., null values, invalid inputs).

10. Limit Triggered Flows per Object

  • Why: Multiple flows on the same object and trigger type (e.g., Before Update) can cause conflicts or performance issues.
  • How:
    • Consolidate logic into a single flow per object and trigger type when possible.
    • Use decision elements to branch logic within one flow instead of creating separate flows.
    • Define a clear order of execution if multiple flows are unavoidable (via Flow Trigger Order in Process Automation Settings).

11. Use Before-Save vs. After-Save Wisely

  • Why: Before-Save flows are faster and don’t consume DML limits, while After-Save flows are better for related object updates.
  • How:
    • Use Before-Save for same-record updates (e.g., setting a field value).
    • Use After-Save for cross-object updates or integrations (e.g., creating child records).
  • Example: Set Account.Status__c in a Before-Save flow; create a related Task in an After-Save flow.

12. Monitor Performance

  • Why: Complex flows can slow down user experience or hit governor limits.
  • How:
    • Avoid excessive loops or large data operations in real-time flows.
    • Use Schedule-Triggered or Asynchronous Paths for heavy processing.
    • Check “Paused and Failed Flow Interviews” for performance issues.

13. Version Control and Documentation

  • Why: Flows evolve over time, and lack of documentation can confuse future developers.
  • How:
    • Save versions with meaningful descriptions (e.g., “Added error handling for null values”).
    • Document the flow’s purpose, key logic, and dependencies in the Description field or external docs.
    • Use comments within the flow for complex sections.

14. Security Considerations

  • Why: Flows must respect user permissions and data security.
  • How:
    • Run flows in System Context with caution; prefer User Context when possible.
    • Validate user inputs in Screen Flows to prevent injection or invalid data.
    • Ensure sensitive data (e.g., SSN) is handled securely (e.g., masked or encrypted).

15. Deactivate Unused Flows

  • Why: Inactive flows clutter the system and can accidentally be reactivated.
  • How:
    • Regularly audit flows using Setup > Flows.
    • Deactivate and archive unused flows, keeping only the active version.

Example Scenario

Requirement: When an Opportunity is closed, update its Stage and notify the owner.

  • Best Practice Application:
    • Flow Type: Record-Triggered (After-Save).
    • Naming: Opportunity_ClosedWon_Notify_After.
    • Bulkification: Use a collection to handle multiple Opportunities.
    • Subflow: Call a reusable “Send Notification” subflow.
    • Error Handling: Add a fault path if the update fails.
    • Testing: Debug with 1 record and 200 records.

These best practices align with Salesforce’s recommendations and community standards.




I have to say, that’s a pretty impressive list. Try your favorite AI tool and see what it comes up with.

Similar Posts