All posts

Use a simple formula to create org-independent record hyperlinks

If you’ve ever built a Salesforce Flow and needed to generate a clickable record URL, you’ve probably run into the temptation to hardcode your org’s…

If you’ve ever built a Salesforce Flow and needed to generate a clickable record URL, you’ve probably run into the temptation to hardcode your org’s domain. Maybe you stored it in a custom label, or maybe you just stuck the production URL into sandbox and decided testing would just have to suffer.

But there’s a better, dynamic way—one that works across orgs without any hardcoded values and without having to sacrifice testing or maintain values in different orgs. It uses the Flow global variable $Api.Partner_Server_URL_260, which gives you the current environment’s server URL of any org you’re in.

✅ The Best Way: Dynamic Record Link Formula

Here’s the one-liner formula:

LEFT($Api.Partner_Server_URL_260, FIND( '/services', $Api.Partner_Server_URL_260)) & {!recordId}

This grabs the base URL of the current Salesforce org—sandbox or prod—and appends the record ID dynamically. It’s safe, simple, and environment-agnostic.

🛑 The Problem with Hardcoded URLs or Custom Labels

Option 1: Custom Label with Org URL

Many teams use a custom label like BaseOrgURL__c set to something like https://acme.my.salesforce.com/.

The issues:

  • You have to maintain separate labels across sandboxes and prod.
  • Migrating flows becomes brittle.
  • It’s easy to forget to update it when cloning orgs or deploying.

Option 2: Hardcoded String in Flow or Apex

Even worse, hardcoding URLs directly into Flow or Apex makes your automation fragile and tightly coupled to the org. It breaks in scratch orgs, and it’s not future-proof.

🧠 Why This Formula Works

$Api.Partner_Server_URL_260 returns something like:

https://acme.my.salesforce.com/services/Soap/u/60.0/00Dxxxxxxxxxxxx

Using LEFT(..., FIND('/services', ...)) trims the URL at /services, leaving just the domain: https://acme.my.salesforce.com

Add a & {!recordId} at the end and you’ve got a complete, dynamic record link that works across any environment.

🔗 Use Cases

  • Displaying a “View Record” link in an email or screen flow
  • Generating links for Slack or Teams messages
  • Building flow-powered notifications or approvals

🧼 Clean, Portable, and No Maintenance

This simple formula keeps your flows clean and portable. No more manual edits per environment. No dependency on custom labels. No risk of URL drift.

If you’re building flows that reference record URLs, use this technique. It’s the cleanest way to stay dynamic and avoid tech debt.

Note: this solution only works in flows or apex, but does not work in formula fields.