Saturday 8 February 2020

Spring 20 Default Record Create Values

Spring 20 Default Record Create Values


Spring 20 introduces something rather reminiscent of URL hacks - the capability to provide default values when creating a record via URL parameters.  Not quite the same though -  for one thing this is a supported mechanism, whereas we were constantly warned against using URL hacks in Classic by Salesforce. For another, this is currently only documented as working on record create, whereas URL hacks worked (although wasn't supported, might not work in the future etc) across most of the later Classic pages.

How It's Done

The first thing you need is the URL to the create page - this takes the form:


e.g. for Account this is :


While for a custom object with an api name of Webinar__c it is:


Next, you need the parameter the defines the defaults:

and then the list of name=value pairs for the fields - again, these are the API names, so the record name would be:

while a custom field would have the API name, including the __c suffix:

(note that I've used '+' to indicate a space in the query part of the URL - I could just as well have used '%32')

Multiple Values

To add multiple default parameter values, use the comma ',' character to separate them - don't use '&' as this will indicate the defaultFieldValues parameter has finished and a new parameter is starting!


All Together Now

Putting all the elements identified above, I have the following URL:

Entering this in my Spring 20 org takes me to the record create page for the Webinar custom object, with the defaults pre-populated:

Relationship Fields

 MyWebinar__c custom object has a lookup to a custom survey object, with the relationship field named Survey__c. When entering information on the create page, I put the text name of the field and choose the entry from the list, so it's tempting to specify the name of the record in the URL. That doesn't end well:

Leaving aside the frankly hilarious idea that I could take an internal error id from Salesforce to my administrator and that would help in any way, it clearly doesn't like the text. This is because the relationship field needs an ID, so if I specify one of those it populates correctly.

Out of curiosity I tried an non-existent ID to see if the error message is any more helpful - it is, and tells me that it can't find the record that the ID refers to, which is much better.

I must also say that in both error cases I love that the plucky Save button sticks around even though things have gone badly wrong. Clicking it doesn't do anything, in case you are wondering.

Related Posts

1 comment: