Git Product home page Git Product logo

sfdx-record-create-url-component's Introduction

Legitimate "URL Hacking" in Lightning Experience

screen shot

Inspired by Brian Kwong's blog post on "URL Hacking" with supported features in Lightning Experience.

This project's purpose is to determine a way to provide the "URL Hacking" in Lightning Experience with supported features in Lightning Experience but without the need of a Flow so that we can have a reusable solution for any object and supporting arbitrary number of fields and data types. This is actually one of the wish items Brian talks about at the end of his blog post.

Creating Custom Button URL

The start of the URL should be /lightning/cmp/c__URL_CreateRecordCmp?, this tells Lightning Experience which component to navigate to. The below table describes the supported parameters to append to the URL. Separate each parameter=value pair with &.

Name Description Required?
objectName API name of the object whose create form to show. Yes
recordTypeId ID of the record type of the new record. No
recordId ID of the current record where user is clicking the button from. Workaround for no cancel behavior customization. No
field name One or more API field names whose default values to populate (e.g. FirstName, Phone, Active__c) No

Examples

Account button that opens the new contact form, pre-populating the first and last name fields:

  • /lightning/cmp/c__URL_CreateRecordCmp?recordId={!Account.Id}&objectName=Contact&FirstName=Doug&LastName=Ayers

Design

In Summer '18, a new interface was introduced, lightning:isUrlAddressable, which allows us to create URLs and pass arbitrary parameters to Lightning Components. Great! So that part is done, no need for Flow, we can create URL buttons similar to how we did in Classic so many moons ago.

However, by navigating to this lightning component as a URL, you are navigating away from the original record page you were on when you clicked the button. The problem with that is there is no way to control what happens when the user clicks the cancel or save buttons in the modal dialog.

When the user clicks the save button, then they are taken to view the new record. This default behavior is acceptable, for now.

When the user clicks the cancel button, though, the modal simply disappears. The user is not redirected back to where they had clicked the button, so they are left with a blank page. This default behavior is not acceptable.

screen shot

To compensate for the lack of control of the cancel behavior, the component supports a recordId URL parameter. When specified in the URL, the record is loaded in the background when the create record modal appears. By the time the user clicks the cancel button, the original record will have been loaded and the user won't notice that they had navigated away to begin with.

screen shot

Next Steps

Please vote for the force:recordCreate event to expose callbacks to customize the modal dialog button behavior:

sfdx-record-create-url-component's People

Contributors

douglascayers avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

sfdx-record-create-url-component's Issues

"+" in parameter not treated as Space for default value

If a default value is specified with a "+" as a space, it doesn't interpret it as a space.

I have a picklist field, that I'm passing "Flat File" to using standard PageReference parameter mapping to create the redirection, and it is replacing the space with a plus ("Flat+File") and then pre-populaing the picklist field with that value, which is invalid.

recordId "pop-under" not working...

I just implemented this, thank you so much!
I believe there may be an issue though: When I opening the link into a new window (using target="_blank") and send "recordId", I see the "new record" popup come up briefly, but then it closes as the underlying record loads. If I do not use recordId parameter (so that the background stays blank), it works. It also works if I do not open into a new window (no "target" on the href)

Critical Update for Summer '19 Prevents use of non-Namespace Parameters...

A Critical Update is being activated in Summer ’19: any URL Parameters utilized in Lightning need to have “namespace” prefix, otherwise they are dropped…
https://releasenotes.docs.salesforce.com/en-us/spring19/release-notes/rn_forcecom_general_namespace_prefix_cruc_reminder.htm

This affects the URL_CreateRecordCmp because the parameters being utilized by it are stripped by Lightning now.

To see this in action: in a sandbox that has Summer '19 (or the Critical Update activated)... this link will not work:
/lightning/cmp/c__URL_CreateRecordCmp?objectName=Case
the screen will refresh and the URL will drop all of the parameters… resulting in a blank screen. (the code errors calling action "c.getFieldDescribeMap" for null parameters)

if you use this link:
/lightning/cmp/c__URL_CreateRecordCmp?c__objectName=Case
you will still get the blank screen after refresh, but notice that the objectName parameter will carry through to the new page. (Still getting a blank screen because the parameter is now starting with c__ which is not expected…)

I'm going to adjust the code (and my URL creation code throughout) to prefix the parameters with "c__"
(Sorry, I wish I was better with git, I'd upload my changes once I make them... but I'm not really familiar with how it works to pull/push/etc... I'll relate my changes below once I make them.)

Blank fieldName Parameters cause failure

If you pass a fieldName parameter with no value for a lookup field (like AccountId), the new record popup will fail.

I fixed by adding check for value to line 72 of the Helper
if ( fieldDescribeMap.hasOwnProperty( fieldName ) && fieldDescribeMap[fieldName].createable && pageRef.state[fieldName] ) {

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.