0

I've read the component developer guide regarding data service components, but I'm not sure if nesting is supported. I am getting the following error when a data service component is a child, but it works fine on the page itself: Uncaught Action failed: c:ResetASDBtn$controller$resetASD [Cannot read property 'CloseDate' of null]

Parent:

 <aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
<aura:attribute name="parentRecordId" type="Id" />
<c:ResetASDBtn recordId="{!v.parentRecordId}"/>
</aura:component>

Child:

<aura:component  implements="force:hasRecordId">
<aura:attribute name="recordId" type="Id" />
<aura:attribute name="opportunityRecord" type="Object"/>
<aura:attribute name="resetDate" type="Date" default="2100-12-01"/>
<aura:attribute name="recordLoadError" type="String"/>
<force:recordData aura:id="oppRecordUpdate"
    recordId="{!v.recordId}"
    fields="CAREStatusListView__c,CloseDate"
    targetFields="{!v.opportunityRecord}"
    mode="EDIT"
    recordUpdated="{!c.recordUpdated}" />

<lightning:button variant="brand" label="Reset ASD"  onclick="{!c.resetASD }" /> 
//...additional logic

Child Controller:

//additional logic
resetASD: function(component, event, helper) {
    var oId = component.get("v.recordId");
    component.set("v.opportunityRecord.CloseDate", component.get("v.resetDate"));
    component.find("oppRecordUpdate").saveRecord($A.getCallback(function(saveResult) {
        if (saveResult.state === "SUCCESS" || saveResult.state === "DRAFT") {
            console.log("Save completed successfully.");
        } else if (saveResult.state === "INCOMPLETE") {
            console.log("User is offline, device doesn't support drafts.");
        } else if (saveResult.state === "ERROR") {
            console.log('Problem saving record, error: ' + 
                       JSON.stringify(saveResult.error));
        } else {
            console.log('Unknown problem, state: ' + saveResult.state + ', error: ' + JSON.stringify(saveResult.error));
        }
    }));
}

})

1
  • 1
    can you please try to reduce your code to the relevant parts of your question?
    – Basti
    Oct 23 '17 at 20:12
0

Parent attribute name also needs to be record id:

<aura:component 
implements="flexipage:availableForRecordHome,force:hasRecordId" 
access="global" >
<aura:attribute name="recordId" type="Id" />
<c:ResetASDBtn recordId="{!v.recordId}"/>
</aura:component>

Works just fine.

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.