You need to sign in to do that
Don't have an account?
PatMcClellan__c
Force Lightning Data Service to load a specific record?
Cross-posting here from the Trailhead forum, where I'm working on the Lightning Components Framework SuperBadge. We're implementing LDS on a page, but NOT using force:hasRecordId. Instead, we're dynamically setting an aura:attribute, and then referencing it in the LDS parameter for recordId. I've been researching this for hours, but all the reference docs and Trailhead modules assume the case where you're using the implicit recordId on the page. No examples I can find where they're setting the recordId and then forcing the reload.
In this case, the id attribute is successfully being set, but LDS isn't loading the record. The error message says: The onBoatSelected handler in the BoatDetails controller must force Lightning Data Service to load the specified record, using logic in the controller.
In the controller, I'm using a reloadRecord command: component.find("service").reloadRecord() where "service" is the aura:id for the force:recordData element.
Is there some other command required to get the LDS to load the record?
Here's the component markup with the force:recordData info:
In this case, the id attribute is successfully being set, but LDS isn't loading the record. The error message says: The onBoatSelected handler in the BoatDetails controller must force Lightning Data Service to load the specified record, using logic in the controller.
In the controller, I'm using a reloadRecord command: component.find("service").reloadRecord() where "service" is the aura:id for the force:recordData element.
Is there some other command required to get the LDS to load the record?
Here's the component markup with the force:recordData info:
<aura:attribute name="id" type="String"/> <aura:attribute name="boat" type="Boat__c"/> <aura:attribute name="boatSimple" type="Boat__c"/> <aura:attribute name="recordError" type="String"/> <aura:handler event="c:BoatSelected" action="{!c.onBoatSelected}"/> <force:recordData aura:id="service" recordId="{!v.id}" mode="VIEW" fields= "Id, Name, Description__c, Price__c, Length__c, Contact__r.Name, Contact__r.Email, Contact__r.HomePhone, BoatType__r.Name, Picture__c" targetRecord="{!v.boat}" targetFields="{!v.boatSimple}" targetError="{!v.recordError}" recordUpdated="{!c.onRecordUpdated}" />Am I screwing up something in the markup?
Even I am facing the similar issue,..i.e. Im not able to set the id attribute, and also the recoerd is not getting loaded...Could you please help me..
This is my code snippet
Will this LDS works other than Component Load or page Load.
For example : In a custom vf page, a Lightning App is loaded and then inside a component in the same app, on a button click in that component , in modal (without component refresh or page load) CRUD operations are included.
Is it possible to use LDS in the above scenario or LDS will work only on Page Load?!.
I learned two things:
1. reloadRecord() method ===> component.find("service").reloadRecord(); ==> We have to use it on the change of the 'recordId' or 'fields' attribute of force:recordData tag. In this superbadge we use it right now in onBoatSelected() handler, but we can call it via any other handler called via like 'recordUpdated' attribute in force:recordData tag
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/data_service_handling_record_change.htm
2. Why to use 'targetFields' over 'targetRecord' ===> For example, for the Name field, v.targetRecord.fields.Name.value is equivalent to v.targetFields.Name.
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/data_service_load_record.htm