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");
}