How to use the lightning/uiRecordApi.updateRecord function in lightning

To help you get started, we’ve selected a few lightning examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github barryhughes1 / pluralSightQuestionnaires_LWCs / force-app / main / questionnaires / lwc / questionnaireAnswer / questionnaireAnswer.js View on Github external
console.log(this.answerValue);
      console.log('this.QuestionnaireQuestionId: ' + this.QuestionnaireQuestionId);
      console.log('this.QuestionnaireReturnedId: ' + this.QuestionnaireReturnedId);
      console.log('this.comments: ' + this.comments);
*/
      let record = {
            fields: {
                Id: this.questionAnswerId,
                // Questionnaire_Returned__c: this.QuestionnaireReturnedId,
                // QuestionnaireQuestion__c:this.QuestionnaireQuestionId,
                Agree_with_Question__c:this.answerValue,
                Comments__c:this.comments,
            },
        };

        updateRecord(record)
            .then(() => {
                this.dispatchEvent(
                    new ShowToastEvent({
                        title: 'Success',
                        message: 'Answer Updated',
                        variant: 'success',
                    }),
                );
            })
            .catch(error => {
               console.log(JSON.stringify(error));
                this.dispatchEvent(
                    new ShowToastEvent({
                        title: 'Error updating record',
                        message: error.message.body,
                        variant: 'error',
github barryhughes1 / pluralSightQuestionnaires_LWCs / 04. Completed Solution / main / questionnaires / lwc / questionnaireLwc / questionnaireLwc.js View on Github external
updateQuestionnaireReturn() {
        // Multiple pages - referential integrity #2 (@kevinv11n)
        console.log('updateQuestionnaireReturn CALLED!!');
        const fields = {};
        fields[ID_FIELD.fieldApiName] = this.questionnaireReturnedId;
        fields[QUESTIONNAIRE_FIELD.fieldApiName] = this.selectedQuestionnaireId;
        fields[TANDC_FIELD.fieldApiName] = this.termsConditions;
        fields[SUBMITTED_FIELD.fieldApiName] = this.questionnaireSubmitted;
        fields[ANSWERED_BY_FIELD.fieldApiName] = Id;
        let record = {fields};
        updateRecord(record)
            .then(() => {
                this.dispatchEvent(
                    new ShowToastEvent({
                        title: 'Success',
                        message: 'Questionnaire Updated',
                        variant: 'success',
                    }),
                );
            })
            .catch(error => {
                this.dispatchEvent(
                    new ShowToastEvent({
                        title: 'Error updating record',
                        message: error.message.body,
                        variant: 'error',
                    }),
github barryhughes1 / pluralSightQuestionnaires_LWCs / 04. Completed Solution / main / questionnaires / lwc / questionnaireLwc / questionnaireLwc.js View on Github external
title: 'Warning',
                    message: 'You must agree to terms and conditions before submitting',
                    variant: 'warning',
                }),
            );

        } else {
            // Multiple pages - referential integrity #2 (@kevinv11n)
            const fields = {};
            fields[ID_FIELD.fieldApiName] = this.questionnaireReturnedId;
            fields[QUESTIONNAIRE_FIELD.fieldApiName] = this.selectedQuestionnaireId;
            fields[TANDC_FIELD.fieldApiName] = this.termsConditions;
            fields[SUBMITTED_FIELD.fieldApiName] = true;
            fields[ANSWERED_BY_FIELD.fieldApiName] = this.answeredBy;
            let record = {fields};            
            updateRecord(record)
                .then(() => {
    
                    const updateEvent = new CustomEvent('updatequestionnairelist', { 
                        detail: {
                            operation: 'Return Submitted',
                            newQuestionnaireReturnID: this.questionnaireReturnedId,
                        },
                        bubbles: true                   
                    });        
                    // Dispatches the event.
                    this.dispatchEvent(updateEvent);   
            
                    this.dispatchEvent(
                        new ShowToastEvent({
                            title: 'Success',
                            message: 'Questionnaire Submitted',
github tsalb / lwc-utils / force-app / main / default / lwc / lwcContactDatatable / lwcContactDatatable.js View on Github external
async clearMailingAddress(row) {
    let recordObject = {
      fields: {
        Id: row.Id,
        MailingStreet: null,
        MailingCity: null,
        MailingState: null,
        MailingPostalCode: null,
        MailingCountry: null
      }
    }
    try {
      await updateRecord(recordObject);
    } catch (error) {
      this.dispatchEvent(
        new ShowToastEvent({
          message: String(error),
          variant: 'error',
        })
      );
    } finally {
      this.reloadTable();
    }
  }
github barryhughes1 / pluralSightQuestionnaires_LWCs / force-app / main / questionnaires / lwc / questionnaireLwc / questionnaireLwc.js View on Github external
updateQuestionnaireReturn() {
        let record = {
            fields: {
                Id: this.questionnaireReturnedId,
                Questionnaire__c: this.selectedQuestionnaireId,
                Terms_and_Conditions__c:this.termsConditions,
                Submitted__c:this.questionnaireSubmitted,
                Answered_By__c:this.answeredBy,
            },
        };
        updateRecord(record)
            .then(() => {
                this.dispatchEvent(
                    new ShowToastEvent({
                        title: 'Success',
                        message: 'Questionnaire Updated',
                        variant: 'success',
                    }),
                );
            })
            .catch(error => {
                this.dispatchEvent(
                    new ShowToastEvent({
                        title: 'Error updating record',
                        message: error.message.body,
                        variant: 'error',
                    }),
github salesforce / base-components-recipes / force-app / main / default / lwc / recordEditUtils / recordEditUtils.js View on Github external
export async function ldsUpdateRecord(newRecord, originalRecord, objectInfo) {
    newRecord.id = originalRecord.id;
    newRecord.apiName = null;
    const newRecordEdit = generateRecordInputForUpdate(
        normalizeRecord(newRecord),
        objectInfo
    );

    const recordToSave = createRecordInputFilteredByEditedFields(
        newRecordEdit,
        originalRecord
    );

    return updateRecord(recordToSave);
}