I have a custom project object, which is associated with Task object. Enhanced Notes are enabled in Project and Task objects. There are scenarios that Project may or may not have tasks, and notes can be at Project or Task level. I am trying to build a report card that hope to report all the projects with their respective tasks (if any) and respective Notes (if any) and the notes under the tasks (if any). So i have come up with two SOQL queries:
-- this returns all the projects and their associated tasks
myLstProject = [Select id, sfdc_project_name__c,SFDC_Status_Description__c, priority__c,priority_Color__c, (select id, owner.name,subject from tasks) from sfdc_project__c];
--- this returns the notes with linked entity ids (could be project ids or task ids), the lstLinkedEntityID is the list built from the #1 query's resultset ( project ids and the task ids ).
myContentDocLink = [select contentdocumentlink.id, contentdocument.title, contentdocument.description ,linkedentity.name, linkedentity.id
from contentdocumentlink where linkedentityid in: lstLinkedEntityID
and sharetype='V' and contentdocument.filetype='SNOTE'];
I can iterator and display the first query data nicely, but i am not sure how to embed the second query result to the first one and show the notes respectively to the project/task. Is there a way in lightning component that nested iteration takes dynamic key for its parent iteration and auto filter out the data?
I was thinking about using Map of List, but I don't have any luck. Also it doesn't seem i can combine those two queries nicely. If it is in Oracle/SQL Server, it can be easily done. Any suggestion is highly appreciated!
private static List<ID> myLstLinkedEntityID = new list<Id>();
private static List<sfdc_project__c> myLstProject = new List<sfdc_project__c> ();
private static List<ContentDocumentLink> myContentDocLink= new List<ContentDocumentLink>();
private static void getNotesHelper (List<ID> lstLinkedEntityID)
{
myContentDocLink = [select contentdocumentlink.id, contentdocument.title, contentdocument.description ,linkedentity.name, linkedentity.id
from contentdocumentlink where linkedentityid in: lstLinkedEntityID
and sharetype='V' and contentdocument.filetype='SNOTE'];
system.debug('in getNotesHelper size: ' + myContentDocLink.size());
// return myContentDocLink;
}
@AuraEnabled
public static List<SFDC_Project__C> getProjectAndTasks()
{
myLstProject = [Select id, sfdc_project_name__c,SFDC_Status_Description__c, priority__c,priority_Color__c, (select id, owner.name,subject from tasks) from sfdc_project__c];
for (sfdc_project__c p: myLstProject)
{
myLstLinkedEntityID.add(p.id);
for (Task t: p.tasks)
{
myLstLinkedEntityID.add(t.id);
}
}
system.debug(myLstLinkedEntityID);
getNotesHelper(myLstLinkedEntityID);
return myLstProject;
}
@AuraEnabled
public static Map<ID, List<String>> fetchNotes()
{
Map<ID, List<String>> objectNoteMap = new Map<ID, List<String>> ();
system.debug('document link size is: ' + myContentDocLink.size());
if (myContentDocLink !=null)
{
for (ContentDocumentLink cl: myContentDocLink )
{
List<String> content = new List<String> ();
String title = cl.ContentDocument.title;
String description = cl.ContentDocument.Description;
content.add(title);
content.add(description);
if(!objectNoteMap.containsKey(cl.LinkedEntity.ID))
{
system.debug('Key: ' + cl.LinkedEntity.ID);
objectNoteMap.put(cl.LinkedEntity.ID, content);
system.debug('New Key ' + content);
}
else
{
objectNoteMap.get(cl.LinkedEntity.ID).add(title);
objectNoteMap.get(cl.LinkedEntity.ID).add(description);
system.debug('Existing Key ' + title );
}
}
}
system.debug ('Map: ' + objectNoteMap);
return objectNoteMap;
}
--- lightning component, where I need one more iteration to show the notes under project/task accordingly
<lightning:layout >
<lightning:layoutitem>
<aura:Iteration items="{!v.lstProject}" var="item">
<lightning:card title="{!item.SFDC_Project_Name__c}" iconName="standard:scan_card" >
<c:DisplayNoteItem item="{!item}" />
<aura:Iteration items="{!item.Tasks}" var="task" indexVar="index">
<li>Task subject: {!task.Subject} </li>
</aura:Iteration>
</lightning:card>
</aura:Iteration>
</lightning:layoutitem>