How to use the lightning/uiRecordApi.createRecord 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 / 04. Completed Solution / main / questionnaires / lwc / questionnaireAnswer / questionnaireAnswer.js View on Github external
createQuestionnaireAnswer() {
      const fields = {};
      console.log('create answer');

      console.log('this.QuestionnaireReturnedId: ' + this.QuestionnaireReturnedId);
      fields[QUESTIONNAIRE_RETURNED_FIELD.fieldApiName] = this.QuestionnaireReturnedId;
      fields[QUESTIONNAIRE_QUESTION_FIELD.fieldApiName] = this.QuestionnaireQuestionId;
      fields[AGREE_WITH_QUESTION_FIELD.fieldApiName] = this.answerValue;
      fields[COMMENTS_FIELD.fieldApiName] = this.comments;

      const recordInput = { apiName: QUESTIONNAIRE_ANSWER_OBJECT.objectApiName, fields };
      createRecord(recordInput)
            .then(QuestionnaireAns => {
                this.questionAnswerId = QuestionnaireAns.id;
                this.Questionnaire_Answer__c = QuestionnaireAns;   

               // sending an update event to the parent questionnaireList component
               console.log('Creating Answer ==> updating list 1');

               const updateEvent = new CustomEvent('updatequestionnairelist', { 
                  detail: {
                     operation: 'New Answer',
                     questionID : this.QuestionnaireQuestionId,
                     newQuestionnaireAnswerID: this.questionAnswerId
                  },
                  bubbles: true
               });        
               console.log('Creating Answer ==> updating list 2');
github barryhughes1 / pluralSightQuestionnaires_LWCs / force-app / main / questionnaires / lwc / questionnaireAnswer / questionnaireAnswer.js View on Github external
fields[QUESTIONNAIRE_RETURNED_FIELD.fieldApiName] = this.QuestionnaireReturnedId;
      fields[QUESTIONNAIRE_QUESTION_FIELD.fieldApiName] = this.QuestionnaireQuestionId;
      fields[AGREE_WITH_QUESTION_FIELD.fieldApiName] = this.answerValue;
      fields[COMMENTS_FIELD.fieldApiName] = this.comments;

/*
        console.log('======= createQuestionnaireAnswer ======');
        console.log(this.answerValue);
        console.log('this.QuestionnaireQuestionId: ' + this.QuestionnaireQuestionId);
        console.log('this.QuestionnaireReturnedId: ' + this.QuestionnaireReturnedId);
        console.log('this.comments: ' + this.comments);
      console.log(JSON.stringify(fields));
*/

      const recordInput = { apiName: QUESTIONNAIRE_ANSWER_OBJECT.objectApiName, fields };
      createRecord(recordInput)
            .then(QuestionnaireAns => {
                this.questionAnswerId = QuestionnaireAns.id;
                this.Questionnaire_Answer__c = QuestionnaireAns;

               // LAST PIECE TO EXPLAIN - Updating the initial JSON
               // Creates the event with the new questionnaire Return ID
               // sending an update event to the parent questionnaireList component
               console.log('Creating Answr ==> updating list');
               console.log('this.QuestionnaireQuestionId: ' +  this.QuestionnaireQuestionId);
               console.log('this.questionAnswerId: ' +  this.questionAnswerId);
               const updateEvent = new CustomEvent('updatequestionnaire', { 
                  detail: {
                     operation: 'New Answer',
                     questionID : this.QuestionnaireQuestionId,
                     newQuestionnaireAnswerID: this.questionAnswerId
                  },
github barryhughes1 / pluralSightQuestionnaires_LWCs / force-app / main / questionnaires / lwc / questionnaireLwc / questionnaireLwc.js View on Github external
createQuestionnaireReturn() {
        const fields = {};
        if(!this.termsConditions) this.termsConditions = false;
        fields[QUESTIONNAIRE_FIELD.fieldApiName] = this.selectedQuestionnaireId;
        fields[TANDC_FIELD.fieldApiName] = this.termsConditions;
        fields[SUBMITTED_FIELD.fieldApiName] = this.questionnaireSubmitted;
        fields[ANSWERED_BY_FIELD.fieldApiName] = this.answeredBy;

        const recordInput = { apiName: QUESTIONNAIRE_RETURNED_OBJECT.objectApiName, fields };
        createRecord(recordInput)
            .then(questionnaireReturned => {
                console.log('QUESTIONNAIRE RETURN RECORD CREATED');

                // The following line is a bad idea - selectedQuestionnaireObj controlled by parent.
                // this.selectedQuestionnaireObj.questionnaireReturnedId = questionnaireReturned.id;

                this.questionnaireReturnedId = questionnaireReturned.id;
                this.questionnaireReturned = questionnaireReturned;

               // LAST PIECE TO EXPLAIN - Updating the initial JSON
               // Creates the event with the new questionnaire Return ID
               // sending an update event to the parent questionnaireList component
               const updateEvent = new CustomEvent('updatequestionnaire', { 
                detail: {
                    operation: 'New Return',
                    newQuestionnaireReturnID: this.questionnaireReturnedId,
github barryhughes1 / pluralSightQuestionnaires_LWCs / 04. Completed Solution / main / questionnaires / lwc / questionnaireLwc / questionnaireLwc.js View on Github external
createQuestionnaireReturn() {
        const fields = {};
        if(!this.termsConditions) this.termsConditions = false;
        fields[QUESTIONNAIRE_FIELD.fieldApiName] = this.selectedQuestionnaireId;
        fields[TANDC_FIELD.fieldApiName] = this.termsConditions;
        fields[SUBMITTED_FIELD.fieldApiName] = this.questionnaireSubmitted;
        fields[ANSWERED_BY_FIELD.fieldApiName] = Id;  // from import

        const recordInput = { apiName: QUESTIONNAIRE_RETURNED_OBJECT.objectApiName, fields };
        createRecord(recordInput)
            .then(questionnaireReturned => {
                console.log('QUESTIONNAIRE RETURN RECORD CREATED');

                // The following line is a bad idea - selectedQuestionnaireObj controlled by parent.
                // this.selectedQuestionnaireObj.questionnaireReturnedId = questionnaireReturned.id;

                this.questionnaireReturnedId = questionnaireReturned.id;
                this.questionnaireReturned = questionnaireReturned;
  
               // sending an update event to the parent questionnaireList component
               const updateEvent = new CustomEvent('updatequestionnairelist', { 
                detail: {
                    operation: 'New Return',
                    newQuestionnaireReturnID: this.questionnaireReturnedId,
                   },
                 bubbles: true
github salesforce / base-components-recipes / force-app / main / default / lwc / recordEditUtils / recordEditUtils.js View on Github external
export async function ldsCreateRecord(newRecord, objectInfo) {
    const normalizedRecord = normalizeRecord(newRecord);
    const recordToSave = generateRecordInputForCreate(
        normalizedRecord,
        objectInfo
    );

    return createRecord(recordToSave);
}