Have a junction object called AccountPublisherAssociation that is a junction between an Account and a custom object called Publisher. I would like to write a query to display all the Publishers that have been selected for a particular account id.
The following SOQL gives me the result with the right record count but with empty values in the name field.
ApexController
@AuraEnabled
public static List < sObject > getCurrentRecords(String ParentId) {
List < sObject > lstOfRecords =
[select Publisher__r.id, Publisher__r.Name from AccountPublisherAssociation__c where Account__c :ParentId];
return lstOfRecords;
}
Javascript Controller Call the function during init
doInit: function(component, event, helper) {
//Call server controller
//Set the existing records
var action = component.get('c.getCurrentRecords');
action.setParams({
"ParentId": component.get("v.recordId")
});
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
var storeResponse = response.getReturnValue();
if (storeResponse.length == 0) {
component.set("v.Message", 'No Records Found...');
} else {
component.set("v.Message", '');
// set searchResult list with return value from server.
}
component.set("v.selectedLookUpRecordsPublisher", storeResponse);
}
if(state == "ERROR")
{
var errors = response.getError();
console.log(errors);
}
});
// enqueue the Action
$A.enqueueAction(action);
},
The above code works well if we directly query the publisher table.
This gives the accurate record count but with empty values i.e it gives 5 rows with empty values for the id and name fields. There are no errors on the developer console as well. Tried the below query with same results as well. I am not sure why the values are null but the count is accurate
[select id, Name from Publisher__c where id in (select Publisher__c from AccountPublisherAssociation__c where Account__c = :accountId)];
Relevant Component Code
This a reusable component that shows a list of pills as the selected Publishers associated with an account.
<aura:component controller="tagListCtrl" Implements="flexipage:availableForRecordHome,force:hasRecordId" access="global">
<aura:attribute name="lstSelectedRecords" type="sObject[]" default="[]" description="Use,for store SELECTED sObject Records"/>
<aura:iteration items="{!v.lstSelectedRecords}" var="selectedRec">
<lightning:pill label="{!selectedRec.Name}" name="{!selectedRec.Id}" onremove="{! c.clear }">
<aura:set attribute="media">
<lightning:icon iconName="{!v.IconName}" size="x-small" alternativeText="icon"/>
</aura:set>
</lightning:pill>
</aura:iteration>
</aura:component>
Tried id
, and Id
but both result in the same issue.