Kolton Dupey · 2025-06-25 · 7 min read
How to Create a Salesforce Utility Bar App That Dynamically Gets the Record ID from the URL
CRM

Have you ever needed to launch a Flow in Salesforce from the Utility Bar
and pass the current record's ID automatically? If you've struggled with
this in the past, you're not alone. Salesforce doesn't pass the
recordId to a utility bar component by default. But with a simple
Lightning Web Component (LWC), you can grab it directly from the URL.This post walks through a complete solution I recently implemented,
including the LWC, Flow setup, deployment using Salesforce CLI, and
real-world use cases.
📍 The Use Case
You're working inside Salesforce and want to quickly launch a screen
Flow related to the record you're viewing. For example:
- Generate a pre-filled form
- Display compliance info
- Kick off a custom automation
You don't want to embed a Flow on every page layout. Instead, you want
something accessible from the Utility Bar, regardless of object.
I personally use this in our Salesforce Org paired with a SMS provider's
API to send text messages to our Leads, Opportunities, and current
clients. I wanted the ability to pull in the current record's
information as default values but also have the option to change to
another Lead, Opportunity, or Client by a lookup field within the flow.
⚠️ The Challenge
When a Flow is embedded on a Record Page, Salesforce automatically
passes the
recordId. But when launched from the Utility Bar, you're
outside the page context—so the recordId is NOT passed.🔧 The Solution: Parse the URL
I created a small but powerful LWC that:
- Reads the current URL
- Uses regex to extract the
recordId - Passes it to any Flow via the
lightning-flowcomponent
📂 File Structure (Salesforce DX project)
This is how the component folder is organized within your Salesforce DX
project.
File structure from within VS Code or code editor of your choice
📄 Code Summary
getRecordIdFromURL.js - Extracts recordId and launches
the flow
I have added console log statements within this JS code to help with
debugging.
This is what a correct parse of the record Id will look like on the
console log on your browser.
getRecordIdFromURL.html - Renders the flow
getRecordIdFromURL.js-meta.xml - Makes component
utility-bar accessible
🚀 Deploying with Salesforce CLI
Use the following CLI commands to deploy to your org:
The above command opens a browser window for you to input your
Salesforce Sandbox credentials and creates a CLI alias "MySandbox" for
that org. This is creating the authenticating to your org to deploy the
package.
This command deploys a specific folder of meta data to the "MySandbox"
org. The folder is where all of our code above should be stored.
🔢 Flow Setup
- Create a new Screen Flow.
- Add a Text Variable named
recordId, mark it as Available for Input. - Use it however you'd like—Get Records, Decisions, Screens, etc.
TIP: You can use this for any record but the
information displayed on the flow can be dynamic based on an early
decision in your flow. The prefix of the Record Id will be unique to the
object. Here is a link from Salesforce for decoding the prefix:
In my Salesforce Org, I wanted to use record information from Leads,
Opportunities, and Accounts. I used a Decision to determine if the
prefix was 00Q (Lead), 006 (Opportunity), or 001 (Account) and then
carried on the flow from there.
🧭 Add to the Utility Bar
- Go to Setup → App Manager
- Edit your Lightning App
- Add a Utility Bar item: select your new
getRecordIdFromURLcomponent
🛠 Troubleshooting Tips
- Confirm your Flow's input variable is named
recordId - Use
console.login JS to validate what's being parsed - Add a decision element in your Flow to detect when
recordIdis blank
🚀 Final Thoughts
This approach turns your Utility Bar into a context-aware launchpad for
automations. It's lightweight, reusable, and Flow-friendly. If you're
frequently working with screen Flows and want maximum flexibility—this
pattern is a game-changer.
– Kolton Dupey
Automation Developer | Salesforce & API Integrator
Want this built for your business?
This post comes from a real engagement. Dealing with something similar? Book a 15-minute call and I'll tell you what it would take.