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
- From set-up, go to Object Manager for the object on which you’ll click the button (Animal, in this case).
- Click “Buttons, Links and Actions.”
- Click “New Button or Link.”
- 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!
- 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.
- 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
- Start at the Object manager for the starting object (Animal), and select Page Layouts. Select the appropriate layout.
- 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 Contact.Account.Id 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.
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.
Hello, I saw that if a Lookup field is not populated it causes an error, is there a way to receive this error if my lookup may not be populated?
The recordId of the starting object doesn’t work for me unfortunately. I suspect the same will be true about the look ups. Could it be something with the new release?
Hmm… It’s working for me. Can you paste in your text and tell me which objects you’re using?
Hi Jessie! what about updating and saving the record at the same time with the URL?
Hi! I’m sorry, but I don’t know. I see you asked on SalesforceBen. Did you get an answer?
Hi Jessie, thanks for your interest
Actually I didn’t. Anyhow, I kept researching, and it seems Salesforce does not allow this possibility.
So URL hacking is only for prepopulating NEW records with specific values, not possible to update with specific values and save in one link…
Have a nice weekend!
Hey Jessie, do you know if we can add the retURL functionality in lightning? I’m trying to create a button that will return a user to the parent record after a child record is created. (i.e. after a contact is created from an account, return to the account record rather than opening up the newly created contact record).
Any help is truly appreciated!
-Jovanny
Hey! Looks like this doesn’t exist yet! upvote it on ideaExchange https://trailblazer.salesforce.com/ideaView?id=0874V000000cXbcQAE
Thank you for the heads up. Will do!
Does this only work for standard objects? I can’t seem to get this to work on a lookup to a custom object. I’ve try every combincation and still no success. I can get it to auto populate if the record Id is hardcode.
/lightning/o/Quote/new?defaultFieldValues=
Project__c=Opportunity.Project__c.Id