How to Find Salesforce Hostnames for URL Redirects in Flow

When doing custom salesforce buttons and actions, knowing what your hostname is and/or the instance you are on is important when trying to add functionality and redirects to other custom or managed package resources. And with Lightning and Apex you have javascript and the URL methods respectively in order to determine your URL and hostname attributes. But in Flow without making calls out to Apex or a Aura/LWC component it can be tricky specially when going from a custom Flow to a managed package URL.

Business Challenge:

  • Create a custom button that launches a flow that validates certain criteria with quote and quote lines.
  • If the quote does not pass the flow validations then present the user a screen with the list of errors.
  • If the quote passes forward the user to the standard page related to ‘Generate Document’. The catch is that the page is part of the CPQ managed package so the URL will need to contain SBQQ.

The popular google search result is to take the partner API URL and parse it. An alternative way is to query the organization table for your instance prefix (NS or CS with a number). You can then forward the user to a URL like this:

“https://sbqq.” + {!instancePrefix} + “” + {!recordId}

The magic is that the system takes this and whether in Lightning or Classic, the system will redirect the user to the correct URL with the appropriate ‘mydomain’ name. You do not need to know the instance or sandbox name or the domain, the system handles all of that automagically by passing it the instance. So the URL you are forwarded to looks something like this:


Here is what I did to solve this within Flow:

  • Created a ‘Get Records’ step and pull from the ‘Organization’ object. There’s only 1 record per instance so no need to worry about which record to pull. Take the defaults unless you want to just set the instance name to a variable.
  • Create a Flow formula variable with this value
  • “https://sbqq.” + {!instancePrefix} + “” + {!recordId}
  • Pass that formula variable to a lightning component that does URL forwarding…and yes I do not have that here in the example as that does not come standard out of the box (yet) but there are tons of simple examples you can copy/paste/create.

As a bonus, how I did the error message is that I created a text variable, for each validation instead of ‘equals’ I used ‘add’ and at the end of the message I wanted to display I put in “LR”. I then created a flow formula that does a substitute on LR and inserts in its place BR() which is a carriage return. Flow does not know how to handle the BR() in the text variable but does in the formula, go figure. This shows up nicely on the error page as a list of things that the user needs to complete or check in order to generate the documents.

Leave a Reply

Your email address will not be published. Required fields are marked *