Home SALESFORCEConfiguration Set Lookup field values in Records Create Page with Default Field Values

Set Lookup field values in Records Create Page with Default Field Values – Spring 20

This post describes about to set Lookup field value using defaultFieldValues. As part of Spring 20 Release its possible to construct the formula to prepopulate the values while creating a new record using custom button or custom links.

As part of Spring 20 Salesforce Release, URL Hacking is back in Salesforce Lightning Experience.

Refer my previous post URL hacking is back in Salesforce Lightning Experience as part of Spring 20 Release:- https://theblogreaders.com/url-hacking-back-salesforce-lightning-experience-spring-20-release/

 

To set Lookup field values using Default Field Values:-

Use Case: Create Contact from Opportunity detail page with prepopulate the Opportunity Account name:

follow the below steps to achieve

Step 1: Setup -> Object Manager -> Select Opportunity Object -> Create a button and enable the button into your opportunity page layout:

/lightning/o/Contact/new?defaultFieldValues=
AccountId={!Opportunity.AccountId}

Step 2: Enable button in Page Layout Setup -> Object Manager -> Select Opportunity Object -> Select Page Layouts -> drag and drop the button from Mobile & Lightning Actions to Salesforce Mobile and Lightning Experience Actions sections

Step 3: Enabled button appeared in the Opportunity Layout

Step 4: Account name automatically populated in creation popup from Opportunity Account Name while clicking the button

Step 5: if notice error is occurred when Lookup value is empty (here Account Name is empty):

Step 6: to resolve above error when the lookup value is empty, use with URLFOR() expression in formula to pass the lookup value in the parameter only if lookup value exists like using IF() condition to check with Blank value using ISBLANK() like below:-

{!URLFOR(‘/lightning/o/Contact/new?defaultFieldValues=’ +
IF(ISBLANK(Opportunity.AccountId), ”, ‘,AccountId=’+Opportunity.AccountId)
)}

Below Demo Video:

This video demonstrate following items:-

  • Set Record Type Id Using defaultFieldValues – Spring 20
  • Enforce User to Select Record Types Using defaultFieldValues – Spring 20
  • Set Date value Using defaultFieldValues – Spring 20
  • Set Custom field value Using defaultFieldValues – Spring 20

Final Notes:-

  • Use URLENCODE if your passing values contain any special characters
  • Remove the Space between your field API Name and Value
  • Use useRecordTypeCheck or recordTypeId before the defaultFieldValues
  • Case Sensitive for recordTypeId
  • Date to Convert as String Using TEXT()
  • Use if using lookup field value passing, if the lookup field is empty then received the error to overcome with with URLFOR()  expression to check ISBLANK() in IF() Condition, refer the this post

Reference:

URL Hacking is back in Salesforce Lightning Experience – Spring 20 Release

You may also like

Leave a Comment