function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Victor VermaVictor Verma 

lwc superbadge 8 issue

Challenge Not yet complete... here's what's wrong:
We can’t find the correct settings for the method handleSave() in the component boatSearchResults JavaScript file. Make sure the method was created according to the requirements, using the correct event, refresh method, correct promises, toast events for success and failure using the constants, and complete error handling.
 
handleSave(event) {
    const recordInputs = event.detail.draftValues.slice().map(draft => {
        const fields = Object.assign({}, draft);
        return { fields };
    });
    const promises = recordInputs.map(recordInput => {
        return updateRecord(recordInput);
    });
    Promise.all(promises)
        .then(() => {
            this.dispatchEvent(
                new ShowToastEvent({
                    title: SUCCESS_TITLE,
                    message: SUCCESS_MSG,
                    variant: 'success',
                })
            );
            this.draftValues = [];
            this.refresh();
        })
        .catch(error => {
            this.dispatchEvent(
                new ShowToastEvent({
                    title: ERROR_TITLE,
                    message: error.message.body,
                    variant: 'error',
                })
            );
        });
}

 
VinayVinay (Salesforce Developers) 
Hi,

We have a separate Trailhead team who can help you with these issues. So, can you please use the below link to reach out to them so that one of the agent will get in touch with you.

Support:https://trailhead.salesforce.com/help

Thank you!

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.

Thanks,
Vinay Kumar
Maharajan CMaharajan C
Hi Victor,

Please refer the below code:

The handle Save method should be like below:

handleSave:
    // This method must save the changes in the Boat Editor
    // Show a toast message with the title
    // clear lightning-datatable draft values
    handleSave(event) {
      this.isLoading = true;
      this.notifyLoading(this.isLoading);
      const recordInputs =  event.detail.draftValues.slice().map(draft => {
        const fields = Object.assign({}, draft);
        return { fields };
      });

      const promises = recordInputs.map(recordInput => updateRecord(recordInput));
    
      Promise.all(promises).then(boats => {
          this.dispatchEvent(
              new ShowToastEvent({
                  title: SUCCESS_TITLE,
                  message: MESSAGE_SHIP_IT,
                  variant: SUCCESS_VARIANT
              })
          );
          // Clear all draft values
          this.draftValues = [];
      }).catch(error => {
          // Handle error
          this.dispatchEvent(
            new ShowToastEvent({
                title: ERROR_TITLE,
                message: error.body.message,
                variant: ERROR_VARIANT
            })
        );
      }).finally(() => {
         // Display fresh data in the datatable
         this.refresh();
      });

    }


Refresh Method:
 
// this public function must refresh the boats asynchronously
    // uses notifyLoading
    @api
    async refresh() { 
      this.isLoading = false;
      this.notifyLoading(this.isLoading); 
      return refreshApex(this.boats);  
    }


Thanks,
Maharajan.C
Mohammad_DanishMohammad_Danish
The use of updateRecord() is not supported for the superbadge. The updated code for the hadleSave() method would be to make use of getRecordNotifyChange() as below:( I have used async/wait pattern as given in salesforce docs https://developer.salesforce.com/docs/component-library/documentation/en/lwc/reference_get_record_notify, you can try for Promise)
async handleSave(event) {
        const updatedFields  = event.detail.draftValues;
       
        await updateBoatList({data: updatedFields })
            .then(() => {
                this.dispatchEvent(
                    new ShowToastEvent({
                        title: SUCCESS_TITLE,
                        message: MESSAGE_SHIP_IT,
                        variant: SUCCESS_VARIANT
                    })
                );
                getRecordNotifyChange([{boatTypeId: this.boatTypeId}]);
                // Display fresh data in the form
                this.draftValues = [];
                this.refresh();
            })
            .catch(error => {
                this.dispatchEvent(
                    new ShowToastEvent({
                        title: ERROR_TITLE,
                        message: error.body.message,
                        variant: ERROR_VARIANT
                    })
                );
            })
            .finally(() => { 
                this.draftValues = [];
            }
            );
    } 
Ali Siddiqui 11Ali Siddiqui 11
@Mohammad_Danish solution works for me.