urlsalesforcevisualforcesalesforce-lightning

Durable Id assignment in URL not working in lightning


Problem Statement: To auto-populate the lookup field I use durable Id assignment with name. For e.g. https://sales--dev.my.salesforce.com/m2p/e?CF00N0l0000051XXX=Contract-00000XXX&inline=1

Notice this -> CF00N0l0000051XXX=Contract-00000XXX ~ durableId=recordName In url.

Now, when the user clicks the New button to create a record on the VF page above URL is loaded in classic and populates the Name in lookup like this

enter image description here

Trying to solve: In lightning, URL is getting overridden by this URL https://sales--dev.lightning.force.com/lightning/o/objectName/new?count=2 Is there a way to achieve the same URL in lightning?


Solution

  • Do you really need it to be an URL hack? Can'y your thing be a quick action? The url prepopulation would be more reliable there and work everywhere.

    URL hacking in lightning is bit simpler, you use field API names instead of IDs. These are decent tutorial: https://www.salesforceben.com/salesforce-url-hacking-for-lightning-tutorial/, https://sfdcdevelopers.com/2020/02/26/url-trick-in-salesforce-lightning/

    So, how do you know where you are, in Classic or LEX. Which URL to use? Have a look at UiThemeDisplayed variable, available in Visualforce and in Apex's UserInfo class.

    IF($User.UIThemeDisplayed == 'Theme4d' || $User.UIThemeDisplayed == 'Theme4t' || $User.UIThemeDisplayed == 'Theme4u', 
        'link for lightning',
        'link for classic'
    )