Search code examples
salesforcesalesforce-lightning

Pull URL via Screenflow in Salesforce


I am trying to pull the URL for whatever record the user is on when they launch my screenflow.

For example if they are on an account I would need the account URL: "https://mydomain--partial.lightning.force.com/lightning/r/Account/00000000000000/view"

If they are on a report, I would need the report URL: "https://mydomain--partial.lightning.force.com/lightning/r/Report/00000000000000000/view?queryScope=userFolders"

My screenflow launches from a utility action.

I'm using the following formula in the screenflow now (LEFT({!$Api.Partner_Server_URL_260}, FIND( '.com', {!$Api.Partner_Server_URL_260} )) + RIGHT({!$Api.Partner_Server_URL_260}, FIND( '.com', {!$Api.Partner_Server_URL_260} )))

The problem is that this returns: "https://mydomain--partial.my.salesforce.com/services/Soap/u/26.0/00000000000"


Solution

  • I solved my own question and wanted to share just in case anyone came across this in the future.

    What I had to do was:

    1. Call the flow in an aura cmp
    2. Get the window location in the cmp and pass it to an input variable in the flow

    CMP:

    <aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction,lightning:isUrlAddressable" access="global" >
        <aura:handler name="init" value="{!this}" action="{!c.init}"/>
        <lightning:flow aura:id="FLOW NAME"/>
    </aura:component>
    

    Controller:

    ({
      init : function (cmp) {
          
        var flow = cmp.find("FLOWNAME");
         var inputVariables = [
            {
                name : 'vCurentlURL',
                type : 'String',
                value : window.location.href,
            }
         ];
        flow.startFlow("FLOWNAME", inputVariables );
      }
    })