A before save flow or an after save flow: when to choose what in Salesforce

Salesforce provides powerful automation tools, like Flow, to streamline business processes and enhance user experience. Flow can be executed at different stages of record processing, such as before or after the record is saved.

  • Published 17 May 2024
  • 4 mins read
A before save flow or an after save flow: when to choose what in Salesforce
Table of contents
Article Highlights
  • Before Save Flow: Utilized for data validation, enrichment, and executing pre-save actions. It operates before the record is saved, allowing modifications and business rule enforcement.
  • After Save Flow: Ideal for post-save actions, calculations with final data, and asynchronous processing1. It’s executed after the record is saved, enabling actions that depend on the record’s final state.
  • The decision between a Before Save Flow and an After Save Flow should be based on performance impact, data availability, and the order of execution in relation to your business process requirements.

But choosing between a Before Save Flow and an After Save Flow requires careful consideration of your specific requirements and the desired outcome.

In this article, we will explore the key differences between the two and the scenarios in which each option is most suitable.

Understanding a Before Save Flow

As the name suggests, a Before Save Flow is executed before the record is saved to the database. It allows you to:

  • Modify field values
  • Validate data
  • Perform calculations
  • Enforce business rules before committing the record.
👉
A Before Save Flow is primarily used for data validation and enrichment purposes.

When to choose a Before Save Flow

Data validation

A Before Save Flow is ideal when you need to validate data entered by users against specific criteria or rules. For example, you can ensure that mandatory fields are populated, check for data consistency, or perform complex data validation logic.

Data enrichment

A Before Save Flow can help enhance the data in a record by populating additional fields or performing calculations based on existing data.

Pre-save actions

A Before Save Flow can execute actions necessary for the record to be saved successfully. For instance, you can check for duplicate records, assign record owners, or perform complex business calculations that impact the final values to be saved.

Understanding an After Save Flow

💾
An After Save Flow is executed after the record is successfully saved to the database. It performs additional actions that may depend on the record's final state or related data.

An After Save Flow can be triggered by record creation, updates, or a combination.

When to choose an After Save Flow

Post-save actions

An After Save Flow is practical when you perform actions that rely on the saved record. For example, sending email notifications, creating related records, updating related data, or triggering external integrations.

Calculations with final data

If you have complex calculations involving the record's final values or related data, an After Save Flow provides access to this updated information.

Async processing

An After Save Flow is also suitable when performing time-consuming or resource-intensive operations that can be deferred asynchronously. This approach ensures that the record is saved promptly while the additional actions are handled in the background.

Considerations when choosing between the two

Performance impact

A Before-save Flow directly impacts the saving process, as any errors or issues encountered during its execution can prevent the record from being saved. On the other hand, an After-save Flow has less impact on the immediate saving process.

Data availability

A Before Save Flow operates on the data provided by the user before saving, while an After Save Flow has access to the final saved record and its related data. Consider the stage at which you require the data for your automation logic.

Order of execution

When utilizing both, it is crucial to consider the order of execution. A Before Save Flow is executed before triggers and workflows, while an After Save Flow is executed after them. This order can influence specific data's availability or subsequent automation behavior.

Make your choice

Choosing between a Before Save Flow and an After Save Flow in Salesforce depends on the specific requirements of your business process.
🔢
A Before-save Flow is ideal for data validation, enrichment, and pre-save actions. In contrast, an After-save Flow is suitable for post-save actions, calculations with final data, and asynchronous processing.

By understanding the key differences and considering the impact on performance and data availability, you can make an informed decision to effectively leverage the appropriate Flow type to achieve your desired automation goals.

Spring Release Updates
Dynamic Forms for Standard Objects
Enhanced support for standard objects, including Account, Contact, and Opportunity, allows for more granular configuration and dynamic layouts, which can streamline metadata tracking and management.
Flow Orchestrator Enhancements
Improved capabilities for orchestrating complex business processes, including error handling and conditional logic, allow Salesforce admins to design workflows that are more easily monitored and tracked over time.
Lightning Web Components (LWC)
Enhanced LWC features include simplified component lifecycle management and new APIs, allowing for more versatile UI designs and better change tracking for developers.
Einstein AI Insights
Salesforce's AI-powered insights offer deeper analytics on customer data, helping businesses make informed decisions and enabling metadata adjustments that align with these insights.
Field-Level Encryption
New encryption options for custom fields ensure sensitive data remains secure, and changes to encryption settings are tracked within Salesforce metadata logs.
Enhanced Metadata API
Expanded capabilities of the Metadata API allow for more granular tracking of changes, particularly for Lightning page layouts and object permissions, streamlining metadata management.
Custom Metadata Relationships
Ability to create relationships between custom metadata types enhances data models and configurations, which can be tracked for efficient management of Salesforce projects.
Permission Set Group Enhancements
Ability to assign permission set groups to profiles directly and manage permission dependencies improves role-based access control, and changes to these groups are tracked automatically.
DevOps Center Updates
Improved integration with Salesforce's DevOps Center facilitates seamless tracking of metadata changes, deployment, and rollback functions, aligning with the article's focus on managing Salesforce metadata efficiently.

Last updated: 11 Jul 2024