1

I have overridden Standard New button on lead object with Aura Component and this Aura calls LWC which contains record edit form to create new lead record.

I have 2 record types Record Type 1 & Record Type 2 defined on Lead Object. So during record creation, If I select Record Type 1 and then cancel the operation, I am able to navigate back to Lead List views. But, when I click on New Button again and this time If I select Record Type 2 and create a record then Lead records gets created in the system with Record Type as Record Type 1. It should have created Record with Record Type as Record Type 2.

I have observed that when I click on New button 2nd time , it does not refresh the component.

Below is the Sample Code that I have written:

Aura :

<aura:component
   implements="lightning:actionOverride,force:lightningQuickActionWithoutHeader,force:hasSObjectName,lightning:hasPageReference"
    access="global">
    <aura:attribute name="selectedRecordId" type="Id" />
    <aura:attribute name="objectName" type="String" />
    <!--Declare Handler-->
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <div>
        <c:newLeadRecord recordTypeId="{!v.selectedRecordId}" SFDCobjectApiName="{!v.objectName}" />
    </div>
</aura:component>

Aura Controller :

({
    doInit: function(component, event, helper) {
        //get record type Id
        var recordTypeId = component.get("v.pageReference").state.recordTypeId;
        component.set("v.selectedRecordId", recordTypeId);
        //get object API name
        var objectApiName = component.get("v.pageReference").attributes.objectApiName;
        component.set("v.objectName", objectApiName);
    }
})

LWC HTML:

<lightning-record-edit-form object-api-name={sfdcObjectApiName} record-type-id={recTypeId} onsuccess={handleSuccess}
        onerror={handleError} density="comfy">
        .....  .........
</lightning-record-edit-form>

Can someone please help me what how to refresh component everytime when you click on Standard New Button? or how to refresh everytime when I cancel the operation or successfully created the record?

2 Answers 2

2

Try to add this to the Renderer.js of your Aura:

rerender : function(component, helper) {
  this.superRerender();
  let recordTypeId = component.get("v.pageReference").state.recordTypeId;
  component.set("v.selectedRecordId", recordTypeId);
}

This should be called automatically each time your Aura appears on the screen.

3
  • Thank you so much Felix. This solution really helps. I just want to understand from learning perspective if instead of Aura if it were LWC, how I re-rendered Parent LWC? using rendercallback?
    – SFDCDJ
    Commented Dec 30, 2021 at 13:34
  • 1
    The rerender method here is invoked by SF Javascript, not from the child. Therefore I'm not sure to understand the question. There are rare occasions when one wants to rerender the whole parent component. Usually one wants to update specific parts of the parent component, and compared to Aura the mechanism in LWC is simpler and clearer: Create and fire a CustomEvent in the child Javascript, add an onevent attribute to the child element in the parent HTML and add an event handler in the parent. Commented Dec 30, 2021 at 14:07
  • 1
    Or maybe you're wondering which Lifecycle hooks of the parent could be used for the same purpose, if the parent was LWC? You'd go for the renderedCallback(), you are right! Hopefully Salesforce will soon enable us to use pure LWC for overwriting standard actions. Commented Dec 30, 2021 at 14:08
0

The issue is that through LWC component, refresh action needs to be fired. I would suggest you to create and call LWC directly using a quick action. Following links can help: https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.use_quick_actions_screen https://developer.salesforce.com/docs/component-library/bundle/lightning-quick-action-panel https://blog.texei.com/refresh-a-record-page-from-a-lightning-web-component-14a5874ff68e

3
  • But my requirement is I want to override standard new button only and we can not call lwc from standard new button.
    – SFDCDJ
    Commented Dec 30, 2021 at 12:01
  • My bad!! In that case why dont u fire any event from LWC and handle it in parent AURA component? Just make sure that in parent handler, you invoke navigation to the record page. Following link may help:developer.salesforce.com/docs/component-library/bundle/… Commented Dec 30, 2021 at 12:18
  • I have tried to fire and event from LWC and capture the same in Aura but the problem is as soon as fire an event, it stops navigation to list view page. it keeps open the component when I click on cancel button. When I checked the log, I found that it's calling doinit method again which launch the same component again.
    – SFDCDJ
    Commented Dec 30, 2021 at 12:20

You must log in to answer this question.

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