The independent daily for Salesforce admins, developers and architects

Curated by Abhinav (opens in a new tab)

Choosing between Custom Metadata Types and Custom Settings for org configuration (opens in a new tab)

You will learn which configuration store fits deployment-time values, which fits per-user or runtime state, and how to migrate between them.

Why read this

The article gives a clear decision rule that you can apply when designing new configuration.

Custom Settings

  • Records are data, not metadata
  • Not in change sets or packages
  • Hierarchy cascade: org, profile, user
  • Count against data storage

Custom Metadata Types

  • Stored as metadata
  • Deploy with change sets and packages
  • Referenced from formulas and Flows
  • Apex cannot edit them at runtime
Custom Settings and Custom Metadata Types differ in how they deploy and in what they can do at runtime

Salesforce orgs need to store configuration that code reads, such as feature flags, endpoint URLs and thresholds. The article contrasts the two classic options, Custom Settings and Custom Metadata Types, and notes that choosing the wrong one tends to cause problems later, often during deployment.

Custom Settings hold org-specific data in two forms: List settings, which are sets of records, and Hierarchy settings, which cascade values from org to profile to user. The cascade is their main advantage, since it allows per-user or per-profile values without code. Their records are data rather than metadata, so they do not travel with change sets or packages, must be recreated in each sandbox and in production, are invisible to the Metadata API, and count against data storage.

Custom Metadata Types store configuration as metadata that deploys with change sets, unlocked packages and the Metadata API. They can be referenced from formulas, Flows, Apex and Validation Rules, and they support protected records in managed packages. Their limits are that Apex cannot create or edit them at runtime, and they have no per-user or per-profile cascade, so one value applies to everyone in the org.

The article’s rule is to ask whether the value changes at runtime or only at deployment. Runtime state such as counters or timestamps belongs in Custom Settings or a Custom Object, while deployment-time configuration belongs in Custom Metadata Types. Per-user or per-profile values call for Hierarchy Custom Settings. Many orgs combine both, using Custom Metadata Types for stable configuration and a Custom Setting or Custom Object for live state.

For migration, the author recommends creating the Custom Metadata Type with the same fields, recreating the records as metadata, and updating references, noting that the getInstance() call changes to the mdt syntax. Migrate one setting at a time, keep the old one until the new one is proven, and check that test classes still cover the code so the 75% deployment gate is not breached.

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

Worth reading?

Recommended

Design a Salesforce security model around user personas (opens in a new tab)

You will learn how to map business personas to a User Field, a Custom Metadata Type, a Permission Set Group and Apex automation, so access stays consistent as features are added.

Why read this

The piece also explains when to use functional versus persona-based Permission Sets and why Profiles should be kept minimal.

  1. Persona set on User record
  2. Custom Metadata Type maps persona
  3. Permission Set Group for persona
  4. Permission Sets grant access
  5. Apex assigns access on save
How a persona assigns a user's access, from the User record through to Apex

The article argues that Salesforce security models often become a fragmented patchwork, and that features can fail on release because users lack the access they need. Its remedy is to build the security model around personas: groups of users who share a functional role and baseline access. The business defines which persona needs which access (create, read, edit, delete) for a feature, and IT implements that access consistently, so the same framework can serve later releases. Shared understanding between IT and the business is treated as essential to making this work.

The approach rests on five pieces. A persona picklist on the User record, whose edits are tightly restricted to administrators, stores each user’s persona. A Custom Metadata Type acts as a maintainable mapping table from each persona to its profile, role, public groups and Permission Set Group, and automation fails if a persona lacks a mapping record. Each persona gets one Permission Set Group, which has no access of its own, so changing a persona’s access means changing its Permission Sets. Those Permission Sets can be organized either by functional capability, which suits features spanning many objects such as Field Service, or by persona, which suits cases with few personas and complex functions, such as a Partner Relationship Management Experience Cloud site. Temporary cross-role duties are handled through an approved exception process, such as an ITSM workflow, while permanent combined roles should become new personas.

The article also recommends keeping profiles minimal: each user gets a custom “Minimum Access” profile, one per license type, with most permissions moved to Permission Sets, since profiles are still needed only for edge cases such as page layouts, login hours and IP ranges. Assignment is automated with Apex through the organization’s trigger framework, which the author prefers over Flows for consistent performance at scale. For teams not ready for the full design, the author suggests starting with Permission Set Groups for the personas a feature and its successors will need, assigned manually at first, and adding the persona field and automation later. The article frames this as a way to meet the Salesforce Well-Architected Framework’s goals of scalability and predictability.

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

Worth reading?

Ten Flow design mistakes that break Salesforce orgs as they scale (opens in a new tab)

You will learn how bulk record processing, database operations inside loops, repeated writes, hard-coded IDs and weak fault handling make Flow fail under load, and how to design around each one.

Why read this

The piece is practical guidance for anyone whose orgs run record-triggered automation at volume.

This Salesforce Ben article, written for architects, lists ten Flow design mistakes that cause failures as orgs grow, and suggests a fix for each. The first concerns treating Flow as a single-record tool: bulk operations from Data Loader or List Views share one transaction’s governor limits, so authors should use before-save flows for same-record updates, tighten entry conditions, and make invocable Apex bulk-safe. The second warns against database operations inside loops, recommending retrieving records before the loop, changing values in memory, and saving a collection once afterwards, with Collection Filters and Transform as alternatives. The third covers writing to the database too often, since each write can fire further automation and cause record-locking, so decisions should come first and writes should be batched near the end.

The next several points cover maintainability, testing and error handling. Hard-coded IDs break when flows move between environments, so the article recommends looking up records by DeveloperName, using Custom Metadata, Custom Labels or Custom Settings. Flows without deliberate fault handling leave failures to Salesforce’s default response, so authors should choose between blocking saves, guiding users, or logging failures, and should understand how rollback differs for unhandled errors, handled faults and explicit rollbacks. Testing with a single record gives little assurance, so the article urges bulk tests of at least 200 records, representative data, and separate logic, transaction-limit and load testing.

The final points address structure and design. Monolithic flows are hard to maintain, so the piece suggests subflows for repeated logic, self-contained processes and frequently changing rules, while warning against too many tiny subflows and recommending grouping flows by business purpose. Transaction boundaries matter because governor limits apply per transaction, and asynchronous paths, scheduled paths, screens, Wait elements and Platform Events can move work out of the original save, with the trade-off that committed changes cannot be rolled back. Screen Flows need care when users click Previous, which can cause duplicates, so the article advises saving at the end and making steps idempotent. Finally, it cautions that data model problems such as data skew, non-selective queries, recreated roll-up functionality and master-detail choices can limit what Flow design alone can fix. The conclusion advises reviewing the highest-volume objects first.

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

Worth reading?

Recommended

Block unwanted outbound emails in Email-to-Case using Custom Metadata and Apex (opens in a new tab)

The reader will learn how to prevent accidental outbound replies in Email-to-Case by storing blocked addresses in a Custom Metadata Type and enforcing them with an Apex trigger on EmailMessage.

Agents frequently reply to internal distribution lists or automated mailboxes during Email-to-Case interactions, causing infinite loops or unintended data exposure. Standard workarounds rely on hardcoded Validation Rules or Apex classes, which demand repeated testing and deployments whenever the blocklist changes.

The proposed solution moves the restriction list into a Custom Metadata Type. Administrators gain direct access to manage blocked addresses through Setup, removing the need for developer intervention or version control cycles for simple address updates.

Enforcement occurs via a before insert trigger on the EmailMessage object paired with a dedicated handler class. The code isolates outbound communications, verifies the fifty hundred parent identifier to limit scope to cases, and compares recipient addresses against the metadata records using case insensitive matching.

When a restricted address appears in the to or cc fields, the trigger applies an error that prevents the message from sending. This architecture keeps the logic modular, avoids interfering with inbound case creation or unrelated email automation, and provides a reusable template for other metadata driven routing rules.

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

Worth reading?

Must-read

Custom Metadata Types as one deployable home for values across Salesforce and Agentforce (opens in a new tab)

You will see how one Custom Metadata Type can feed formulas, Validation Rules, Flow, Apex and Agentforce actions, and where those references stop working.

Typed into each tool

  • Thresholds in formulas
  • Defaults in Flows
  • Feature switches in Apex classes
  • Each change means finding every use

Custom Metadata Types

  • One deployable home for values
  • Travels through source control
  • One record per region plus Default
  • Read via $CustomMetadata reference
One deployable home replaces values typed into each formula, Flow or Apex class

The article argues that developers often hard-code business values such as thresholds, defaults, feature switches and mappings into formulas, Flows and Apex without noticing, which makes later changes hard to trace. Custom Metadata Types offer a central, deployable home for these values. Unlike Custom Settings or Custom Objects, which hold data, Custom Metadata holds configuration that ships with application code through source control and CI/CD. The author illustrates this with a Deal_Policy__mdt type holding a shared maximum discount and regional records for large-deal amount, default discount and approval threshold, selected by region name.

The piece then maps where references work. Formula Fields, Validation Rules and field defaults can use a three-part reference (type, record name, field), but the formula must name a fixed record, so it cannot pick a region from opportunity data. Long text area fields cannot be referenced, and the formula editor does not list Custom Metadata fields for defaults, though typing the reference still works. Flow can query the type with Get Records, match a region, and fall back to the Default record, and it can also use the literal reference. Apex uses getInstance with a similar fallback. Custom Permissions are kept separate, since they govern what a user may do while Custom Metadata governs the values.

Agentforce cannot read $CustomMetadata references directly, so the workaround is an invocable Apex action that loads the policy and returns the values, which the Agent Script maps into variables before answering. Lightning App Builder component visibility does not accept Custom Metadata references. On record pages a Formula Field can bridge the value, though that adds a field, and App and Home pages must read the data in Apex, through @wire, or via Dynamic Interactions.

To assess impact, the article recommends Setup’s Where is this used? option or a Tooling API query of MetadataComponentDependency, which lists the Apex classes and Validation Rules that depend on a field. It also notes that an attempt to build an LWC editor that showed these dependencies from Apex was complicated by the authentication setup REST calls require. Finally, it outlines platform limits: 200 types per org (350 with certified managed packages), 100 fields per type, and a 10 million character budget where each text area reserves 255 characters regardless of use. Process Builder allows 15 Custom Metadata formula references per process. The author concludes that teams should treat business values as configuration, centralize them, and keep track of where each reference works and where it does not.

Read the original at Andy in the Cloud (opens in a new tab)

Worth reading?