I am trying the default the account Id when creating the contact. But I am unable to save the contact record. I am getting account id from console.log.

Please suggest me what am I doing wrong here.

handleSaveContact: function(component, event, helper) {
    component.set("v.newContact.AccountId", component.get('v.ConAccountId'));
    var recordaction=component.get('v.ContactId')==null?'contactRecordCreator':'ldsContactEdit';
    component.find(recordaction).saveRecord(function(saveResult) {
        if (saveResult.state === "SUCCESS" || saveResult.state === "DRAFT") {
            // record is saved successfully
        } else if (saveResult.state === "INCOMPLETE") {
            // handle the incomplete state
            console.log("User is offline, device doesn't support drafts.");
        } else if (saveResult.state === "ERROR") {
            // handle the error state
            console.log('Problem saving contact, error: ' + JSON.stringify(saveResult.error));
        } else {
            console.log('Unknown problem, state: ' + saveResult.state + ', error: ' + JSON.stringify(saveResult.error));

Thanks, Lakshmi


component.find(recordaction) take the aura-id which you have assigned to the force:recorddata in cmp. for example

<force:recordData aura:id="record"
    targetFields ="{!v.simpleRecord}"

in this case it will be component.find(record)...
  • The aura-id is dynamic based on below expression. My problem is I am not able default account when creating new contact. var recordaction=component.get('v.ContactId')==null?'contactRecordCreator':'ldsContactEdit'; – Lakshmi Nov 11 '19 at 14:22
  • you cant create aura-id dynamically you have to give some static value – User6670 Nov 11 '19 at 14:44

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.