Last active
October 28, 2016 09:18
-
-
Save madmax983/44f3ce76ffc226730a1934438a20a48a to your computer and use it in GitHub Desktop.
Fun with Lightning Data Service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<aura:component > | |
<aura:attribute name="recordIds" | |
type="List" | |
access="public" | |
description="An array of Ids"/> | |
<aura:attribute name="records" | |
type="Map" | |
description="The records!" | |
default="{}"/> | |
<aura:attribute name="errors" | |
type="Map" | |
description="The errors!" | |
default="{}"/> | |
<aura:dependency resource="markup://force:recordPreview" /> | |
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/> | |
<lightning:button aura:id="logRecords" | |
label="Console.log records" | |
onclick="{!c.logRecords}" /> | |
{!v.body} | |
</aura:component> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
({ | |
doInit : function(component, event, helper) { | |
var recordIdList = component.get("v.recordIds"); | |
for(var i = 0; i < recordIdList.length; i++){ | |
var nestedRecordString = "v.records." + recordIdList[i]; | |
var nestedErrorString = "v.errors." + recordIdList[i]; | |
$A.createComponent( | |
"force:recordPreview", | |
{ | |
"aura:id": recordIdList[i], | |
"layoutType": "FULL", | |
"recordId": recordIdList[i], | |
"targetRecord": component.getReference(nestedRecordString), | |
"targetError": component.getReference(nestedErrorString) | |
}, | |
function(newRecordPreview, status, errorMessage){ | |
if (status === "SUCCESS") { | |
var body = component.get("v.body"); | |
body.push(newRecordPreview); | |
component.set("v.body", body); | |
} | |
else if (status === "INCOMPLETE") { | |
console.log("No response from server or client is offline.") | |
// Show offline error | |
} | |
else if (status === "ERROR") { | |
console.log("Error: " + errorMessage); | |
// Show error message | |
} | |
} | |
); | |
} | |
}, | |
logRecords: function(component, event, helper){ | |
var recordIdList = component.get("v.recordIds"); | |
for(var i = 0; i < recordIdList.length; i++){ | |
var nestedRecordString = "v.records." + recordIdList[i]; | |
console.log(component.get(nestedRecordString)); | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Lightning Data Service is only exposed in Lightning Experience and Salesforce1, so make sure that is where your component lives. https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/data_service_considerations.htm