The independent daily for Salesforce admins, developers and architects

Curated by Abhinav (opens in a new tab)

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

Lessons from building a Flow Version Cleaner on the Tooling API (opens in a new tab)

You will learn how to choose between the Tooling API, Metadata API and Apex Metadata for deleting flow versions, and how to handle authentication, object dependencies and state across asynchronous jobs.

Why read this

The piece also sets out safeguards for destructive metadata automation.

  1. Keep the active flow version
  2. Keep newer versions under review
  3. Keep recent inactive versions as fallback
  4. Delete flow interviews via callouts
  5. Delete remaining obsolete flow versions
The cleaner's flow version decision sequence, from protected versions to safe deletion

The author built an open-source Flow Version Cleaner to prune obsolete flow versions in orgs with hundreds of flows. The tool keeps the active version, keeps newer versions that may be under review, and retains a configurable number of recent inactive versions as a fallback. Requirements were refined during the build, once it became clear that version numbers alone do not show which versions are safe to remove.

The article compares the Apex Metadata namespace, the Metadata API with destructive changes, and the Tooling API. The Tooling API was chosen because it lets each flow version be queried and deleted individually at run time, so one failure does not roll back the whole run. Authentication uses Named Credentials rather than the running user’s session, since session IDs can be null in asynchronous work and should not carry the permissions of whoever started the job. Flow interviews must be deleted before flow versions, and because Apex does not allow a callout after DML in the same transaction, both steps use callouts. Versions owned by managed packages cannot be deleted by subscribers.

For asynchronous work, the author recommends building an explicit payload between jobs, since inner-class fields can arrive null without any error, and using one snapshot of org state for both the decision and the action. Destructive metadata work should run in dry-run mode first, record every candidate, and isolate failures, because deleted metadata cannot be restored from the Recycle Bin.

Read the original at Salesforce Architects (opens in a new tab)

Worth reading?