I want to display list of contacts based on the accountId.In the component's helper,I am able to get the accountId in debug logs but when I use lightning:recordViewForm inside an aura:iteration tag then it doesn't show error and does not display any records either. Please let me know the issue. Here's the code.
Server-Side Controller
public static List<Contact> getContacts(List<ID> accountIDs){
return [select Id,FirstName,LastName from contact
where AccountId in : accountIDs];
}
Component:
<aura:component implements=flexipage:availableForRecordHome,
force:hasRecordId,
controller="MyContactController">
<aura:attribute name="contactList" type="List"
<aura:handler name="init" value="{!this}" action="{!c.FetchContactList}"/>
<aura:if isTrue="{! not( empty( v.recordId))}">
<aura:iteration items="{!v.contactList}" var="con">
<lightning:recordViewForm recordId="{!con.Id}" objectApiName="contact">
<lightning:outputField fieldName="{FirstName}" />
<lightning:outputField fieldName="{LastName}" />
Client-Side Controller:
FetchContacts : function(component,event,helper) {
var action = component.get("c.getContacts");
var accId=component.get('v.recordId');
action.setParams({"accountIDs" : accId});
action.setCallback(this,function(response)
{
var state=response.getState();
if (state === "SUCCESS")
{
var conList=response.getReturnValue();
component.set("v.contactList",conList);
}
});
$A.enqueueAction(action);
})