26

With Lightning Experience, we can't use url hacks anymore. I'm fine with that, as this was not a supported solution. However, behind this technical hack was a business need: pre-populate field on record creation, often with different values depending on where you're coming from.

I tried to play with sforce.one to pass some parameters and as I expected I was not able to pass any parameter.

My question is: Is there a way to pre-populate fields on record creation (or have you heard of it on the roadmap), or should we just forget about this business need for now with Lightning Experience ?

Obviously, as we're starting to do impacts analysis on existing orgs for clients wishing to switch to Lightning Experience, this would be a big step back.

  • Dont think any prepopulation is possible unless you build your own components for that – Mohith Shrivastava Nov 10 '15 at 23:15
  • 1
    You could use quick actions instead of buttons. – Jenny B Nov 12 '15 at 22:16
  • I know, but that's not really what I want. Sometime the info I need to pre-populate is not as easy to get as what can be done with Quick Actions. Also, this means maintaining different layouts. – Fabien Taillon Nov 13 '15 at 10:50
  • How exactly do you want it then? Buttons mean maintaining different layouts as well. – Robin De Bondt Feb 29 '16 at 13:07
  • 2
    I would like it to be like today with url hacks: opening the creation page of an object, but with fields prepopulated. I only have to maintain my object layout, not my object layout + my Quick Action layout. Also, with url hacks, it was possible to use apex in the middle to have complex logic to determine which value should be used. – Fabien Taillon Feb 29 '16 at 13:13
3

The Spring '20 release brought the URL hack for prepopulating field values to Lightning! So you can once again achieve this with custom buttons (not Javascript buttons) and links much like we used to in Classic.

Spring '20 release note: Navigate to a Record's Create Page with Default Field Values

Where: This change applies to Lightning Experience in all editions. This change doesn’t apply to Lightning Out, Lightning communities, or the Salesforce mobile app.

How: To construct a custom button or link that launches a new record with prepopulated field values, use this sample formula:

/lightning/o/Account/new?defaultFieldValues=
    Name={!URLENCODE(Account.Name)},
    OwnerId={!Account.OwnerId},
    AccountNumber={!Account.AccountNumber},
    NumberOfEmployees=35000,
    CustomCheckbox__c={!IF(Account.SomeCheckbox__c, true, false)}
| improve this answer | |
  • Could you elaborate this in more detail? I tried to apply this, but all I get are errors, e.g. Error-ID: 522682101-111545 (-1922518417) With fixed values for the fields it's working perfectly, but the {!Account.Xyz} thing does not work for me. – Sander de Jong Mar 26 at 10:55
  • Are you starting from an Account record page in Lightning when navigating to that URL? – Bow-chicawow-ers Mar 26 at 17:37
7
+100

For declarative use cases, Salesforce PM Kamyar Seradjfar recently did a blog series on removing javascript hacks for Lightning Experience. His suggestion for this use case is to use Quick Actions with pre-populated fields by value or formula: https://developer.salesforce.com/blogs/developer-relations/2016/09/take-the-first-steps-ways-you-can-replace-javascript-buttons.html

For code use cases, Lightning Data Service allows developers writing custom Lightning Components creating new records to pass in default field values.

See the defaultFieldValues param in the createRecords() method, documented here: https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/data_service_create_record.htm (Lightning Data Service is in Developer Preview for Winter '17, which means the force:recordPreview component may only be used in Developer Edition orgs.)

Edited to add: there is a new Trailhead module on this topic: Lightning Alternatives to JavaScript Buttons

| improve this answer | |
  • The necessity to Create a new Lightning Component makes this choice very hard. Usually we want to re-use standard layout with values pre-filled. I was wondering how Salesforce do it with Calendar. This is the best example of pre filled form, you can click Any Date and Create New Event dialog automatically have the date selected to the day you clicked on. There seems to be a way to set date values dynamically here. I would like to replicate the exact same thing. – VarunC Feb 9 '17 at 7:20
  • We can use Quick action to pre-populate values, but how to add quick action as list button in related list. Its not possible. If we create VF page button, then Force:createrecord event will not be handled by one app container. So, we can't use VF also. So, in short we can't pre-populate values if we are using URL Hack in related list button. – Rajendra Singh Nagar Apr 26 '17 at 10:35
1

As of the Summer '17 release, this is now possible when using the force:createRecord Event:

Lightning Events - Force:createRecord

Check out the section called "Prepopulating Field Values". This will hopefully make Lightning easier to develop for!

| improve this answer | |
  • Yes, that`s right. An example is: var createAcountContactEvent = $A.get("e.force:createRecord"); createAcountContactEvent.setParams({ "entityApiName": "Contact", "defaultFieldValues": { 'Phone' : '415-240-6590', 613 Reference force:createRecord 'AccountId' : '001xxxxxxxxxxxxxxx' } }); createAcountContactEvent.fire(); – Leisure Dec 5 '17 at 8:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.