0

I have a Aura component on custom tab of Account Record page , on Aura button click opens a LWC pop-up to create custom object record. After saving the record, the pop-up will close but the scrolling is not working on the record page. I want to refresh the Aura and to show list of records that are created from LWC on that custom tab in lightning record page.

LWC:

<template>
        <div class="modal-body">
            <br />
            <lightning-card>
                <lightning-record-edit-form
                    record-id={recordId}
                    object-api-name="ParentObject__c"
                    record-type-id={parentId}
                    onsuccess={handleSuccess}
                    onsubmit={handleSubmit}
                    onerror={handleError}
                                        >
                    <lightning-messages> </lightning-messages>
                    
                    <template>
                        <div class="slds-grid slds-wrap">
                            <!-- <template if:true={fields}>-->
                            <template for:each={parentfields} for:item="f">
                                <div key={f.Id} class="slds-col slds-size_1-of-2">
                                    <lightning-input-field field-name={f.APIName}> </lightning-input-field>
                                </div>
                            </template>
                            <!--</template>-->
                        </div>
                    </template>
                </lightning-record-edit-form></lightning-card
            >
            <br />
        </div>
        <div slot="footer">
            <template>
            <lightning-button class="slds-m-top_small slds-p-right_medium" variant="brand" onclick={handleSubmit} name="save" label="Save"> </lightning-button
            ></template>
        </div>
    
</template>

Js:

import { LightningElement, track, api } from 'lwc';
import getRecordTypeId from '@salesforce/apex/CreationController.getRecordTypeId';
import getRecordTypeDevName from '@salesforce/apex/CreationController.getRecordTypeDevName';
import { RefreshEvent } from 'lightning/refresh';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { NavigationMixin } from 'lightning/navigation';
export default class CreationLwc extends NavigationMixin(LightningElement) {
    DisplayText = false;
    @api size;
    @api objectName;
    @api recordId;
    @api fieldSet;
    @track fields;
    @track systemfields;
    @track isModalOpen = true;
    @api PortfolioRecordTypeName;
    @api PortfolioRecordTypeId;
    @api PortfolioRecordTypeDevName = 'Test';
    @api accrecordId;
    @api showOFields = false;
    @api showTFields = false;
    @api portAccountId;
    @api selectedPortfolioId;
    @api showPortfolio = false;
    isLoading = false;
    @api isSystemFields = false;
    account;
    

    openModal() {
        this.isModalOpen = true;
    }
    closeModal() {
        this.isModalOpen = false;
        this.dispatchEvent(new RefreshEvent());
    }
    submitDetails() {
        this.isModalOpen = false;
    }
    
    handleOTChange(event) {
        console.log('You selected an account: ' + event.detail.value);
        if (event.detail.value === 'Owner') {
                        this.getFieldsForOwner();
                        this.getFieldsForChild();
            this.showOFields = true;
            this.showTFields = false;
            this.showPortfolio = false;
            //this.connectedCallback();
        } 
        } else if (event.detail.value === '') {
            this.showOFields = false;
            this.showTFields = false;
        }
    }
    
    getFieldsForOwner() {
        //this.template.querySelector('c-modal').show();
        getForm({ recordId: this.recordId, objectName: 'parent__c', fieldSetName: this.PortfolioRecordTypeDevName })
            .then(result => {
                console.log('Data:' + JSON.stringify(result));
                if (result) {
                    this.fields = result.Fields;
                    this.error = undefined;
                }
            })
            .catch(error => {
                console.log(error);
                this.error = error;
            });
    }
      
        handleSubmit(e){
        
                const inputFields = e.detail.fields;
                this.template.querySelector('lightning-record-edit-form').submit(inputFields);  
        
        
        }
        handleSuccess(event) {
        console.log('onsubmit event recordEditForm' + event.detail.id);
                this.createRelationship( event.detail.id, this.accrecordId, 'Owner');
                this.closeComponent();
    }
    handleError(e) {
        //this.template.querySelector('[data-id="message"]').setError(e.detail.detail);
        e.preventDefault();
    }

       
    closeComponent() {
        this.isModalOpen = true;
        const close = new CustomEvent('close');
        this.dispatchEvent(close);
    }
       
}

Aura Component:

<aura:component access="global">
    
    <aura:attribute name="key" type="String"/>
    <aura:attribute name="selectedId" type="String" />
    <aura:attribute name="cRecordType" type="String" />
    <aura:attribute name="cRecordTypeDeveloperName" type="String" />
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <aura:registerEvent name="NewCAPPReloadEvent" type="c:NewCAPPReloadEvent"/>
    <c:CreationLwc onsenddata ="{!c.refreshNew}"></c:CreationLwc>
    <aura:html tag="style">  
        .slds-modal__container{max-width: 75rem !important;width:80% !important;}
        <!--.slds-modal__content { overflow: inherit; overflow-y: inherit;}-->
    </aura:html>
    
      <c:CreationLwc aura:id="CreationLwc" RecordTypeName="{!v.key}" accrecordId="{!v.currentRecordId}" CRecordTypeId="{!v.cRecordType}></c:CreationLwc>  
      
    <aura:if isTrue="{!v.showSpinner}">
        <lightning:spinner variant="brand" alternativeText="Loading"/>
    </aura:if>
    <lightning:layout>
        <lightning:layoutItem padding="around-small" alignmentBump="left">
            <lightning:button variant="Neutral" label="{!'Add '+ v.key + ' Vendor'}" aura:id="addVendor"
                              value="systemCreation" onclick="{!c.openModal}"/>
        </lightning:layoutItem>
    </lightning:layout>
    
</aura:component>

Aura js controller:

     openModal : function(component, event, helper){
            helper.getcappRecordTypeDeveloperName(component, event, helper);
            var recTypeName = component.get("v.key");
            component.find('CreationLwc').LWCFunction(); 
            
        },
refreshNew :function(component, event, helper){
        console.log('??????????');
        var appEvent = $A.get("e.c:NewCAPPReloadEvent"); 
    }
7
  • Can you show the Aura component? Aug 5, 2023 at 5:27
  • @AntonKutishevsky added the Aura component.
    – Anjali
    Aug 7, 2023 at 2:09
  • What if you leave only one CreationLwc component inside Aura? Aug 7, 2023 at 6:16
  • @Anton Kutishevsky Tried that yesterday but didn't work
    – Anjali
    Aug 7, 2023 at 14:38
  • Can you update the question with the latest version of code? The existing code can't be even deployed. Aug 8, 2023 at 17:08

1 Answer 1

0

This can be done using customevent. We have to dispatch the event from lwc component and handle on Aura Component.

Dispatch Event from handle success.

this.dispatchEvent(new CustomEvent('refreshdata'));

SRC: https://trailhead.salesforce.com/content/learn/projects/communicate-between-lightning-web-components/communicate-from-child-to-parent

Handle dispatched event from LWC in Aura:

<c:CreationLwc aura:id="CreationLwc" RecordTypeName="{!v.key}" accrecordId="{!v.currentRecordId}" CRecordTypeId="{!v.cRecordType} onrefreshdata="{!c.refreshData}"></c:CreationLwc>

NOTE: Above code taken from question only to answer.

You can write refresh logic in Aura method refreshData.

I hope this will help you.

You must log in to answer this question.

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