0

Is it possible to use NavigationMixin.Navigate to navigate to a new Case and retain the relationship to the current Account? I have a lightning component with a navigation button that uses the following Page Reference to start a new case from the Account page:

this.accountHomePageRef = {
            type: 'standard__objectPage',
            attributes: {
                objectApiName: 'Case',
                actionName: 'new'
            }
        };

In short, I want the new Case to be releated to the Account.

1 Answer 1

1

what you're saying is you need to populate a field value (in this case the accountId) with the account record where the button was clicked on. unfortunately setting default values on navigateMixin in LWC is not yet supported:

LWC counterpart to Aura's force:createRecord event

What you can do instead is create an Aurawrapper component to enclose your LWC. then fire a custom event from lwc that will be responded to by the parent Aura, then Aura launches a createRecord event with the passed account id.

on LWC js:

  @api recordId; // build-in keyword to store the current acct record id on page


  _onCreateCase() {
    this.dispatchEvent(new CustomEvent('onCreateCase', {
            detail: { acctId : this.recordId },
        });

on Aura wrapper cmp:

<c:childLwc onCreateCase="{!c.handleCreateCase}"/>

controller js:

handleCreateCase: function(component, event, helper) {
      var acctId = event.getParam('acctId');
      var createEvent = $A.get("e.force:createRecord");
            createEvent.setParams({
               "entityApiName" : "Case",
               "defaultFieldValues" : {
                  "AccountId" : acctId
            }
        });
        createEvent.fire();
}

https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.events_sending_to_aura_components

2
  • It seems like what your explaining will create record, but then how do I open up that record programmatically?
    – Mr. B
    Aug 30, 2019 at 19:04
  • its the same as a New form with fields populated. You will still have to click on Save or Cancel. Once saved then you will be routed to the new record automatically. Aug 31, 2019 at 2:04

You must log in to answer this question.

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