0
@api recordId;
filiale;
accManager;
pbName;
pbId;

get statutAffectation() {
    return "PR";
}


connectedCallback() {
    setTimeout(() => {
        getRecord({recordId: this.recordId})
            .then(result => {
                this.filiale = result;
                this.accManager = result.AccountManager__c;
                this.pbName = result.Name;
                this.pbId = result.Id;

                console.log('filiale SixNergieCompteAssocie__c',this.filiale.SixNergieCompteAssocie__c );
            })
            .catch(error => {
                const evt = new ShowToastEvent({
                    title: 'Error!',
                    message: 'error',
                    variant: 'error',
                    mode: 'dismissable'
                });
                this.dispatchEvent(evt);
            });
    }, 5);
}


handleSubmit(event) {
    this.template.querySelectorAll("lightning-record-edit-form").forEach(element => {element.submit();});
}

handleSuccess(event) {
    event.preventDefault();
    const evt = new ShowToastEvent({
        title: 'Success!',
        message: 'record created',
        variant: 'success',
    });
    this.dispatchEvent(evt);
    this[NavigationMixin.Navigate]({
        type: 'standard__recordPage',
        attributes: {
            recordId: this.recordId,
            actionName: 'view'
        }
    })
    this.dispatchEvent(new RefreshEvent());


}

HTML :

<template>
<template if:true={filiale}>
    <lightning-card  variant="narrow"  title="Créer une filiale" icon-name='utility:classic_interface' >
        <lightning-record-edit-form
                object-api-name="Filiale__c"
                onsubmit={handleSubmit}
                onsuccess={handleSuccess}>
            <lightning-messages></lightning-messages>
            <div class="slds-grid" style=margin:20px>
                <div class="slds-col slds-size_1-of-2">
                    <lightning-input-field field-name="Name" value={pbName}> </lightning-input-field>
                    <lightning-input-field field-name="SixNergieCompteAssocie__c" value={accManager} required="true"> </lightning-input-field>
                    <lightning-input-field field-name="ActivityPortfolio__c" value={pbId}> </lightning-input-field>
                    <lightning-input-field field-name="SixNergieFiliale__c" value={SixNergieFiliale__c} required="true"> </lightning-input-field>
                    <lightning-input-field field-name="SixNergieCodesociete__c" value={SixNergieCodesociete__c}> </lightning-input-field>
                </div>
                <div class="slds-col slds-size_1-of-2">
                    <lightning-input-field field-name="SixNergieStatutdaffectation__c" value={statutAffectation}> </lightning-input-field>
                    <lightning-input-field field-name="SixNergie_CodeReseauCommercial__c" value={SixNergie_CodeReseauCommercial__c}> </lightning-input-field>
                    <lightning-input-field field-name="SixNergieStrate__c" value={SixNergieStrate__c}> </lightning-input-field>
                    <lightning-input-field field-name="SixNergie_LibelleAccordCommercial__c" value={SixNergie_LibelleAccordCommercial__c}> </lightning-input-field>

                </div>
            </div>
            <div class="slds-m-top_large slds-grid slds-grid_align-center slds-align–absolute-center">
                <lightning-button variant="brand" type="submit" label="Save" >
                </lightning-button>
            </div>
        </lightning-record-edit-form>
    </lightning-card>
</template>

Bouton action using LWC , its placed on the Parent Record page layout , its goal is to create a child record and to refresh the standard related list of the child record

The standard related list isn't updated every time i create new child record (sometimes its refreshed only when create the first record )

3

0

You must log in to answer this question.