Not sure if this is possible, but I'd like to be able to prepopulate the value in a lookup field when creating a new record.


I have a lookup field to a custom Office object on my Opportunity object. On my User object, I have a picklist that correspond to the names of each record of the Office object. When I create a new Opportunity, I would like for the Office field on my new Opp to be prepopulated with the Office that is named on the running user's record.

E.g. User record has office picklist of "New York", Branch record with name "New York" exists in system. User creates a new opp and the "New York" field is already populated in the Branch lookup field.

I tried using "Lightning URL hacking" with a custom URL button using something like: /lightning/o/Opportunity/new?defaultFieldValues=Office__c=New York, but naturally passing a string here doesn't work and causes the field to not appear in the new record UI and causes an error upon saving.

Any help or confirmation that this is even possible is appreciated. Note: I want this to exist as a button on the Opportunity list view.

2 Answers 2


For this i would suggest the new lwc headless action where you can have apex controller to query for the id of the Office record based on the Name from the user record. Then fire from the invoke method navigation to a new record page with a predefined Office field on Opportunity.

Posting the code for the navigation as it could be hard to find.

    type: 'standard__objectPage',
    attributes: {
        objectApiName: 'Account',
        actionName: 'new'
    state: {
        defaultFieldValues = 'AccountNumber=ACXXXX,CustomCheckbox__c=true,Name=Salesforce%2C%20%231%3DCRM,NumberOfEmployees=35000,OwnerId=005XXXXXXXXXXXXXXX',
        nooverride: '1'
  • Interesting solution. I will give it a try. Jul 30, 2021 at 17:44

For a more declarative solution, a screen flow should work although it probably ends with a redirect within a custom component.

Create a new URL List Button based on the URL of the flow

enter image description here

Within the flow you can do the following:

  1. Get user information based on current user Id
  2. Get relevant Office record Id based on user picklist field
  3. Present a screen to "finish" completing the opportunity and set the default value for the lookup field within that screen (or don't even show it if it's not necessary)
  4. Create Opportunity object

If you have a lot of fields on your "new" screen, re-creating the screen may be more trouble than it's worth - so you can re-direct in a similar manner as Damecek's answer with a custom component (Navigate Everywhere is an example of such).

At that point, you may wonder why bother with the screen flow - but, it's highly dependent on your team's strengths/resources and whether this idea will ever delve into some differences (ex. I want a different "new" screen for this one button) where the screen flow may be easier to make changes to and adapt.

  • 2
    Also a great solution. In this case we do have many fields on the New Screen but I'll pitch it as an option. Jul 30, 2021 at 17:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .