Quantcast
Channel: LWC not refreshing related list count after creating new record - Salesforce Stack Exchange
Viewing all articles
Browse latest Browse all 2

LWC not refreshing related list count after creating new record

$
0
0

On contact object, the standard new button is overridden with a LWC component. From account object i try to create contact.

Before creating contact count is 1

enter image description here

After creating a contact, it sill show 1 m but actually its two

enter image description here

After clicking viewAll

enter image description here

Unless and untill i refresh the browser, the count won't get populated properly. I know this is a caching issue. But is there any workaround

HTML

<template>
    <div class="slds-theme_default">

        <template if:true={openmodel}>
            <div class="demo-only">
                <section role="dialog" tabindex="-1" aria-labelledby="modal-heading-01" aria-modal="true" aria-describedby="modal-content-id-1" class="slds-modal slds-fade-in-open">
                    <div class="slds-modal__container">

                        <header class="slds-modal__header">
                            <button class="slds-button slds -button_icon slds-modal__close slds-button_icon-inverse" title="Close" onclick={closeModal}>
                                <lightning-icon icon-name="utility:close" size="medium">
                                </lightning-icon>
                                <span class="slds-assistive-text">Close</span>
                            </button>
                            <h2 id="modal-heading-01" class="slds-text-heading_medium slds-hyphenate">Test</h2>
                        </header>
                        <div class="slds-is-relative">
                            <div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1" style="height: 50vh;">
                                <div class="slds-p-around_x-small">
                                    <lightning-input label="FirstName" class="firstName"></lightning-input>
                                    <lightning-input label="LastName" class="lastName"></lightning-input>
                                    <lightning-input type="Phone" label="Phone" class="phone"></lightning-input><br />
                                    <lightning-input type="Email" label="Email" class="email"></lightning-input><br />
                                    <lightning-input label="Account" class="accountId" value={accId}></lightning-input><br />
                                </div>
                            </div>
                        </div>
                        <footer class="slds-modal__footer">
                            <lightning-button variant="brand" label="Save" onclick={handleClick}>
                            </lightning-button>
                        </footer>
                    </div>
                </section>
                <div class="slds-backdrop slds-backdrop_open"></div>
            </div>
        </template>
    </div>
</template>

JS -

import {
    LightningElement, track, api, wire
} from 'lwc';
import {
    NavigationMixin
} from "lightning/navigation";
import CONTACT_OBJECT from '@salesforce/schema/Contact';
import FIRSTNAME_FIELD from '@salesforce/schema/Contact.FirstName';
import LASTNAME_FIELD from '@salesforce/schema/Contact.LastName';
import PHONE_FIELD from '@salesforce/schema/Contact.Phone';
import EMAIL_FIELD from '@salesforce/schema/Contact.Email';
import ACCOUNTID_FIELD from '@salesforce/schema/Contact.AccountId';
import {
    createRecord
} from 'lightning/uiRecordApi';

export default class Modalspinner extends NavigationMixin(LightningElement) {

    @track spinner;
    @api recordId;
    @track openmodel = true;
    @track accId = '0012v00002InPVmAAN';
    @track cntId;


    handleClick() {

        const fields = {};
        fields[FIRSTNAME_FIELD.fieldApiName] = this.template.querySelector('.firstName').value;
        fields[LASTNAME_FIELD.fieldApiName] = this.template.querySelector('.lastName').value;
        fields[PHONE_FIELD.fieldApiName] = this.template.querySelector('.phone').value;
        fields[EMAIL_FIELD.fieldApiName] = this.template.querySelector('.email').value;
        fields[ACCOUNTID_FIELD.fieldApiName] = this.recordId;
        const recordInput = {
            apiName: CONTACT_OBJECT.objectApiName,
            fields
        };
        createRecord(recordInput)
            .then(result => {
                this.message = result;
                this.cntId = JSON.parse(JSON.stringify(this.message)).id;
                this.redirect();
            })

    }
    redirect() {
        this[NavigationMixin.Navigate]({
            type: 'standard__recordPage',
            attributes: {
                recordId: this.cntId,
                objectApiName: 'Contact',
                actionName: 'view'
            },
        });
    }
}

Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images