The independent daily for Salesforce admins, developers and architects

Curated by Abhinav (opens in a new tab)

How the Salesforce order of execution sequences flows, triggers and validation (opens in a new tab)

You will learn the rough sequence in which Salesforce runs Flows, Apex triggers, Validation Rules and after-save automation when a record is saved, and why that order matters when several automations touch the same record.

Why read this

The article is a general overview rather than a detailed reference.

  1. Initial record submission
  2. Before-save Record-Triggered Flows
  3. Before Apex triggers
  4. Validation and duplicate rules
  5. Save to database, not yet committed
  6. After triggers and after-save flows
  7. Commit and post-commit operations
The main stages Salesforce runs when a record is saved

When a record is created, updated or deleted, Salesforce runs several kinds of automation in a defined sequence. The article says this matters because multiple automations touching the same record can produce unexpected results, repeated updates or errors. Understanding the sequence helps teams troubleshoot and avoid needless complexity.

The process starts with the initial submission, whether from the user interface, the API, Apex, Data Loader or an external application. Before-save Record-Triggered Flows then run before the record is written to the database, and are described as efficient for simple field updates because they avoid an extra save. Before Apex triggers follow, with a short example that sets a default value on a Contact description. Validation Rules and duplicate rules run before the save completes.

Once the record is saved to the database, the transaction is not yet committed, so later errors can still roll the changes back. After triggers and after-save flows then run, handling tasks such as creating related records, sending notifications or starting further processes. The article also notes that legacy workflow, escalation and assignment rules can cause extra updates that re-run parts of the sequence. After a successful transaction, the changes are committed and post-commit work such as Queueable Apex, future methods and scheduled paths can run.

The article closes with common mistakes: several Flows on one object without reviewing their order, duplicating field updates across Flows and Apex triggers, ignoring recursion, and skipping tests for API updates. Its advice is to review existing automation on an object before adding a new Flow, trigger or Validation Rule.

Read the original at dev.to (opens in a new tab)

Worth reading?

Check what else runs on an object before shipping AI-Generated changes (opens in a new tab)

You will learn a repeatable way to list the active Flows, Validation Rules and triggers on an object using the Salesforce CLI and pandas, so a reviewer can see what a change will collide with before it ships.

  1. Export active Flows with SOQL
  2. Export active Validation Rules
  3. Export active triggers via Tooling API
  4. Filter the exports by object in pandas
  5. Attach the tables to the ticket for review
The article's method for finding existing automation on an object before shipping an AI-generated change

The article argues that an AI-drafted Flow, Apex class or Validation Rule must be checked against everything else already running on the same object. Before review, the author suggests finding that automation first, since a clean-looking change can clash with an existing rule, loop with another Flow, or overwrite a field a batch expects to be empty.

The method uses the Salesforce CLI to export active Flows with a SOQL query on FlowDefinitionView, and active Validation Rules and triggers through the Tooling API. Triggers are matched on their object, while Flows have no dedicated object field, so the author scans API name, label and description instead, which is imperfect but faster than opening every Flow. A short pandas script then filters the three exports for a chosen object such as Opportunity and produces a review agenda.

The author adds that managed package automation will also show up in these results. Managed items cannot be edited but can still fire after a change, so they belong in a separate list. The tables should be attached to the ticket so the next reviewer does not have to rerun the queries.

The piece also proposes three test cases a model often skips: a record that must be blocked with a clear message, a record that must pass even when a field arrives late, and the same change run by a non-admin user. It lists reasons to wait a day before shipping, such as a missing description, tests that check coverage rather than the business rule, or a field the model invented. The article is practical and short, and the queries are the main takeaway.

Read the original at dev.to (opens in a new tab)

Worth reading?

Recommended

Rehearse a Salesforce Data load locally before uploading to the Org (opens in a new tab)

You will learn how to simulate a Salesforce data load against your project's triggers, flows and Validation Rules on your own machine, catching refused rows before any reach the org.

Why read this

The piece is a product walkthrough, so treat its claims about the runtime's fidelity with some caution.

  1. Map the CSV onto an object
  2. Simulate rows in a rolled-back transaction
  3. Fix refused rows and simulate again
  4. Upload to Org
How a data load is rehearsed before it reaches the org

The article argues that a Salesforce data load is effectively a deploy: each row runs through the org’s triggers, Validation Rules and flows, and problems usually surface only after the rows are in. It presents Renmy runtime, a local Apex runtime that runs the same automation on a developer’s or admin’s own computer against an embedded database, with no org, Scratch Org or sandbox needed. The piece is a vendor product walkthrough, so its claims about how closely the runtime matches Salesforce should be read with caution. The article points to a public parity record, which it says lists where the runtime matches the platform and where it does not.

The walkthrough runs in IntelliJ IDEA through the plugin Renmy Runtime - Salesforce IDE. The user opens the Salesforce DX project their developers keep in version control, which supplies the triggers, flows and Validation Rules. They then load a CSV in the plugin’s Data Loader, map its columns to object fields, and flag unreadable cells before anything runs. Pressing Simulate processes the rows in batches of 200 inside a transaction that is rolled back, and reports which changes would be made and which rows would be refused, with the platform’s own error messages. The user fixes the file and simulates again as often as needed, and only then uses Upload to Org to send the same file to a chosen org, with a confirmation that names the org and row count. The example is an invoice update in which three rows fail a Validation Rule and three dates cannot be read.

The article also describes a Workbench for editing individual records with automation switched on, and a Save as Fixture option that turns rows into test data for developers. It is explicit about the limits: the rehearsal cannot see automation that exists only in the org until it is retrieved, and for updates the referenced records must also exist locally, where Clone Org Data can copy a slice of the org down. The org remains the final authority. The article also says the rehearsal does not contact an org and keeps source, schema and data on the local machine, and that the Free tier covers the Data Loader and Simulate. It describes the Pro tier as free during the public beta, with a listed price of $19 a month afterwards. It presents the tool as suited to admins with no coding skills, though a developer’s project checkout is needed.

Read the original at dev.to (opens in a new tab)

Worth reading?

Four rules for constraining an AI agent that deploys to Salesforce (opens in a new tab)

You will learn a design for letting an AI agent handle Salesforce deploys safely: a fixed action menu, approval gates, org-checked results and logged, capped runs.

Why read this

The reader comes away with a concrete set of guardrails to consider.

  1. Plan reviewed and approved
  2. Check-only validation in production
  3. Human clicks to deploy
  4. Org queried to verify results
The agent works through three human approval gates before production changes

The author argues that the slow part of a Salesforce deploy is usually assembling the package, choosing tests and target org, and interpreting failures, which are language tasks suited to a model. Deployment itself is not, so the agent is designed around four rules.

First, the model never touches an org. It receives no credentials, shell or sf CLI access, only a fixed menu of actions such as validate, deploy, run tests, query and retrieve. Code checks its parameters and performs the action with the sf CLI and git.

Second, humans approve at three points: the plan, which shows components, target org, tests and risk; a changed plan, when a retry alters components or scope; and production, where a check-only validation runs before a human deploys, including destructive changes. Sandbox steps run automatically while everything stays green. Third, success is verified by querying the org, not taken from the model, and the summary is written from that evidence table. Fourth, every run is logged, with a cost cap and a limit of three retries.

The model’s role is limited to turning a request into a reviewable plan and turning a failed deploy into a plain explanation, such as a test that does not set a new checkbox and so trips a new Validation Rule.

Read the original at dev.to (opens in a new tab)

Worth reading?