Spring ’20 URL Hack Explained

Spring ’20 brings us a revised version of a classic admin’s old favorite: the URL hack, the ability to pass field values via the URL. Let’s try it now with a custom button.

Read the release notes: Navigate to a Record’s Create Page with Default Field Values.

Use Case

The Ugly Dog Adoption Agency wants to click a button on the Animal record (parent) to create a new Treatment Plan record (child), and have a few fields automatically filled in. In this video, I start on the dog Grover’s record and click the button to create a new Treatment Plan. The lookup fields Animal and Vet Assigned are pre-populated.

Instructions

  1. From set-up, go to Object Manager for the object on which you’ll click the button (Animal, in this case).
  2. Click “Buttons, Links and Actions.”
  3. Click “New Button or Link.”
  4. Fill out label, name, description, Display Type of “Detail Page Button”, choose desired behavior, and leave Content Source as “URL.” Be very careful when writing out your formula. Spacing is important! custom button1
  5. HOW TO PASS THE RECORD ID OF STARTING OBJECT. The first value I want to populate is Animal on the Treatment Plan with the Record ID of the Animal I’m starting from. animal url hack
  6. HOW TO PASS THE VALUE OF A LOOKUP FIELD
    Vet_Assigned__c={!Animal__c.Primary_VetId__c}

For my second field assignment, I populate the field Vet Assigned on the Treatment Plan with the value of Primary Vet on the Animal record. (These are both lookups to a Contact).

On the left, I type in the API Name of Vet Assigned. On the right, I use the drop down lists for “Select Field Type” and “Insert Field.” When I look for the merge field for Primary Vet, my choices are Primary Vet and Primary Vet ID. Choose the one with ID. Save the button.

Add to the Page Layout

  1. Start at the Object manager for the starting object (Animal), and select Page Layouts. Select the appropriate layout.
  2. Find your new button under “Mobile and Lightning Actions” (don’t be lured by that tempting choice of “Buttons”!) Drag it down to the “Salesforce Mobile and Lightning Experience Buttons” section. Save.

More Examples

Huge thanks to Aaron Crear for showing me this example. His button creates a new Opportunity from an Account.

/lightning/o/Opportunity/new?defaultFieldValues=Market__c={!Account.Market_PL__c},Region__c={!Account.Region_pl__c},Client_Leader__c={!Account.OwnerId},AccountId={!Account.Id}

Here’s one that surprised me. From the Contact record, you populate the Account ID with {!Account.Id}, rather than an account field. This button takes the Rainier Valley Food Bank from the contact record to creating a new custom Food Bank Visit record and pre-populates the client and the household(Account in Nonprofit Success Pack).

/lightning/o/Food_Bank__c/new?defaultFieldValues=Food_Bank_Client__c={!Contact.Id},Household__c={!Account.Id}

See more examples in this discussion on the Trailblazer community.

One Comment

  1. Is there a version of this Lightning URL hack for Related List buttons? When I click “New Quote” on an Opportunity’s related Quotes list, I want to pre-populate Account, Opportunity, Sales Rep, etc.

    Reply

Leave a Reply to Andy Cancel reply