0

Hello I've been working on a LWC for some months already, I'm close to finally finish it, for this I want to be able to save the changes of a LWC dual list box, once it's saved I'd like to refresh the browser. I'd like to achieve this two actions by pressing one single button "SAVE". Is it possible to do?

THE PROBLEM

I have 2 dual list boxes: -1stdualbox: Left side->Queues from ORG - Right Side->Queues from a selectedUser -2nddualbox: Left Side->Users from ORG- Right Side->Users from a selectedQueue

On this picture if I select Queue Bank from the search bar, I can see the users from the org and users that belong to this Queue, I added the user Sebas Vettel to the Queue Banking.

enter image description here

Now, without refreshing the page, when I click on Sebas from the search bar if I scroll down I'll see the other dual list that show all the queues where Sebas belongs to, however as you can see in the picture the information didn't update in the UI, buf I check the User info in the ORG page I can see that now Sebas belongs to 3 Queues, the new one Banking plus the two others that we was part of already.

enter image description here

Back End from User Sebas Vettel is updated: I want this to be visible in the UI, after clicking "SAVE".

enter image description here

For the moment I have the save method working, it is saving all the information I change in the dualbox, however I can't figure out what method should I use to also reload the page.

I'm using refresh Apex, it keeps saving different actions more than once without refreshing the page which I'm happy with. Before adding this line I had to reload the page every time after I clicked the save button, so I could do more changes.

As I've mention the changes are being saved in the backend, however the information on the UI from the dual list box it's not getting updated after I save changes and that's why I want to be able to have a button than besides saving ,refreshes the page as well.

HTML

  <div class="slds-align_absolute-center"  slot="footer">
                                <lightning-button
                                    variant="brand"
                                    label="Save"
                                    onclick={saveChangesUser}>
                                </lightning-button>
                            </div>

JS

saveChangesUser(){
            
            let updatedBool = false;
            this.disableBool = true;

            if ( JSON.stringify( this.selectedUsers ) != JSON.stringify( this.updatedUsers ) ) {
                updatedBool = true;
            }
            if ( updatedBool == true ) {
            addRemoveUsers( {groupId:this.selectedObj,
                selectedUsers : this.selectedUsers, updatedUsers : this.updatedUsers } )
            .then( result => {
                console.log( 'Result ' + JSON.stringify( result ) );
                let message;
                let variant;
                if ( result === 'Successful' ) {
                    message = 'Successfully Processed!';
                    variant = 'success';

                } else {
                    message = 'Some error occured. Please reach out to your Salesforce Admin for help!';
                    variant = 'error';
                }
                const toastEvent = new ShowToastEvent( {
                    title: 'Your changes have being saved',
                    message: message,
                    variant: variant
                } );
                
                this.dispatchEvent (toastEvent );
                this.dispatchEvent ("$A.get('e.force:refreshView').fire();");
                return refreshApex (this.result);
               
            } )
            .catch( error => {
                console.log( 'Error' + JSON.stringify( error ) );
            } );
            this.buttonBoolUsers = true;
        } else {
            alert( "No changes made!!!" );
        }
    }

Thank you all.

4
  • 1
    You can't use $A methods in LWC, they are for Aura only. Why do you want to refresh the entire page? What problems are you experiencing? See the X-Y Problem for more details.
    – sfdcfox
    Oct 7 '21 at 14:39
  • I've updated the question to make it more clear. Please feel free to have a look. @sfdcfox
    – jbuch
    Oct 7 '21 at 15:31
  • I've updated the problem @glls
    – jbuch
    Oct 7 '21 at 15:32
  • What have you tried so far? What part of it isn't working? I can't see anything in your code that is trying to navigate anywhere after save.
    – Nick Cook
    Oct 8 '21 at 1:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.