Avoid Hard Coded Links In Salesforce

Avoid Hard Coded Links In Salesforce

Thanks Yoda.

Part 1-Do not Do It My Son

Salesforce Screen Flows and Email templates are great, but how do we account for external site links within templates and screen flows? Say I want to build a screen to allow the user to click a link and see the details of a created case or another record.

For internal Salesforce links we already have a tested and true system! using the $api resource within flow, so this formula will give us a direct link to an internal page

HYPERLINK(LEFT({!$Api.Partner_Server_URL_260}, FIND('/services', {!$Api.Partner_Server_URL_260}))& {YourVarHere} , "TextGoesHere")

How to get the $api into a formula resource within flow:

No alt text provided for this image

So This is great and all for internal links , but since the $api formula will only give us the internal page link, what about site links? here is a admin 1 will try to implement, hardcoding the site link into the template (-:

No alt text provided for this image

Stop right There Criminal Scum! if you're thinking to yourself this is a good System for links, please stop. take a break. drink some tea. go out and have a bite to eat. you will always forget to change a link or a template in a flow when moving and refreshing environments

Sadly, admin one's solution never got past the code review. and he took a long break to think about what he did in the naughty chair.

No alt text provided for this image

Here, Admin 2 will try to help, creating a custom label to house the baseline link to the site, using the same baseline Custom label for each link in a flow. Admin 2 will get a nice mention in the weekly for sure.

No alt text provided for this image
No alt text provided for this image


While this is a more valid case, what about that pesky overhead when moving and refreshing environments? can we really create a truly dynamic flow where the links are derived from the site itself? yes we can!

Admin 3 is here for the rescue! using the Site And site Detail Objects and some more fun stuff on the way, Including the great package from #unofficalsf that allows us to run a SOQL query within flow.

Part 2-The Good Stuff

First we will get to know the site and Site Detail objects a bit, for every Site(we we called community before) we setup we create a few records, for the site object here is a simple query to show us some fields

No alt text provided for this image

we will query the site from where it's name assuming we have a few sites within the org and the name is known(no reason it should be changed when moving environments),again the site represents each site we set up

Select Id,Name

from site where Name='YourSiteName'

For each Site record we have a Site Detail record housing the the real and accurate link within the SecureUrl field

Select Id,SecureUrl from SiteDetail where DurableId='SiteId'

No alt text provided for this image

So 'SiteId' will be the hardcoded id we got from the last query(don't worry , in flow this will be mostly dynamic).

good. we got this far.

here is the basic flow, it will run in system mode, since in admin's 3 case non admin users will also run the flow to get the site details

No alt text provided for this image

Let's Run over A to D real quick

A-A get element to get the site id, simple enough

No alt text provided for this image


B-Run A Soql Query to get the site detail record. well you a smart peep, why all this trouble? we will have to install an external package to run a query, have you gone crazy there admin 3? unfortunately Flow does not support querying the Site detail object from the Site Id from a get element. this is in lieu for calling our overstressed caffeinated out resident Dev. read about this great tool here

https://unofficialsf.com/a-graphical-soql-query-builder-for-flow/

No alt text provided for this image

Anyhow you save the query as a text template and insert it into the action

No alt text provided for this image

Admin 3 had to loop the results and get the site detail within the flow since for now the SOQL builder will only output collections, using the DurableId field

No alt text provided for this image

(don't punch me, I know not to use get inside a loop, since this loop has only one result it should be fine, using another package to parse id's within a collection was unfeasible time wise )

here we are at D! assigning this result to a Var to use in a Master flow

No alt text provided for this image
No alt text provided for this image

And finally *drumroll* using the Subflow in a master flow and adding a hyperlink formula to create the link within a screen in a flow

No alt text provided for this image

Environment 1

No alt text provided for this image

Environment 2

No alt text provided for this image

So Admin 3 got a pat on the back. end of story.

To view or add a comment, sign in

Others also viewed

Explore content categories