0

I'm trying to recreate the record creation modal for an Opportunity created from a non-standard related list on Account. I've heard you can override the standard New button with lightning components.

The reason why I want to override the record creation modal is for the purpose of prepopulating fields on the record creation modal page, which as we know, is a pain in Lightning. In classic you can use the good ol URL hack but unfortunately this doesn't work in Lightning. Please don't point me towards quick actions, global actions, or publisher actions, as I would like to retain my related list buttons.

This guy overrode the record type selection modal, thus turning it into this: Custom record type selection modal

which is cool, but I'd like to take that a step further and recreate the record creation modal that is displayed when you click 'Next: Standard record creation modal
Is this possible? I'd guess that instead of invoking c.createRecord when the Next button is clicked, you'd invoke another lightning component that displays a custom record creation modal (instead of the standard one).

2
  • Have you thought about using quick actions? You can pre-populate fields using them too. If you really want to override the new view with a custom lightning component, I'd recommend option is using lightning:recordForm developer.salesforce.com/docs/component-library/bundle/…
    – Ranga
    Commented Jul 18, 2018 at 21:54
  • I ran into issues using quick actions on custom related lists in LEX. I played around a bit with lightning:recordForm but can't get it to prepopulate values on the record creation modal. Commented Jul 20, 2018 at 0:12

1 Answer 1

0

As for your question:

Is this possible?

The answer is Yes.

Now for the below:

The reason why I want to override the record creation modal is for the purpose of prepopulating fields on the record creation modal page

Your use case of pre-populating the record creation window will be solved using force:createRecord. This is what you will need to do:

  1. Create the record type selection component, which you will use to override the New button
  2. On click of Next from that component, you will need to:
    • Invoke force:createRecord event where you will be able to pass on the record type id, and default values attribute which will be pre-populated on the next screen.

Here's the snippet from the documentation about this attribute.

Prepopulates fields on a record create panel, including fields not displayed on the panel. ID fields and rich text fields can't be prepopulated. Users must have create access to prepopulated fields. Errors during saving that are caused by field access limitations do not display error messages.

And here's the code snippet from the documentation as how you can pre-populate the values on the record creation.

var createAcountContactEvent = $A.get("e.force:createRecord");
createAcountContactEvent.setParams({
    "entityApiName": "Contact",
    "defaultFieldValues": {
        'Phone' : '415-240-6590',
        'AccountId' : '001xxxxxxxxxxxxxxx'
    }
});
createAcountContactEvent.fire();
2
  • 1
    Worked perfectly, and I was able to pull in the AccountId dynamically! Thank you. Commented Jul 19, 2018 at 18:37
  • @user3430245 glad to have been able to help here
    – Jayant Das
    Commented Jul 19, 2018 at 20:34

You must log in to answer this question.

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