2

I was rendering the person contact details using lightning record edit form. Updating the person contact details using force:recordData lightning data service.

If i'm updating the person contact details using the saveRecord of data service, in success call back im getting the person account id instead of person contact Id.

Markup:

<aura:component implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" >
<aura:attribute name="recordError" type="String" access="public"/>
<aura:attribute name="contactInstance" type="Contact" access="public" />
<aura:attribute name="record" type="Contact" access="public"/>

<lightning:recordEditForm aura:id="submit-sobject" 
                          objectApiName="Contact" 
                          recordId="0034100002BTXzA" >
    <lightning:messages />                 
    <lightning:inputField fieldName="Name" onchange="{!c.bindChangedValues}" />
</lightning:recordEditForm>

<force:recordData aura:id="recordHandler"
                  recordId="0034100002BTXzA"
                  fields="Name"
                  targetRecord="{!v.record}"
                  targetFields="{!v.contactInstance}"
                  targetError="{!v.recordError}"
                  mode="EDIT" /> 

<lightning:button variant="brand" label="Save" title="Save" onclick="{!c.save}"/>

Controller:

({
bindChangedValues : function(component, event, helper) {
    var targetCmp = event.getSource();        
    var contactInstance = component.get("v.contactInstance") || {};
    contactInstance[targetCmp.get("v.fieldName")] = targetCmp.get("v.value");        
    component.set("v.contactInstance", contactInstance);

},
save : function(component, event, helper) {
    console.log('contact Instance-->', JSON.stringify(component.get("v.contactInstance")));
    component.find("recordHandler").saveRecord(
        $A.getCallback(function(saveResult) {                    
            if(saveResult.state === "SUCCESS") {
                console.log('saveResulId', saveResult.recordId);
            }
        })
    );
}

})

enter image description here

Is this is known issue/ behaviour or i'm missing anything here.

0

Person accounts are special cases. Once person account is enabled in your org, creating a person account internally creates two records (One to represent contact and one to represent associated account)

In general - Account can have multiple contacts, but for person accounts its always 1-to-1.

The behavior is described very nicely in below post:

(Person Accounts & PersonContactId - how are these related?: https://success.salesforce.com/answers?id=90630000000hsNXAAY).

Person Account Documentation

  • i agree with you person accounts are some special cases. even though if you update a person contact it should return the person contact id. If we update any person contact using apex code, it will return the only person contact id not the person account id. – Yaswanth Tikkisetti Jun 17 '18 at 16:51

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.