You need to sign in to do that
Don't have an account?
Jonathan Wolff 7
Combine results of two wrapper lists into one and order by create date
Hello,
I have a component that shows results of task and event query in 2 seperated Lists. I want the combined results to be filtered by create date and be limited to 30 results.
So I see results of tasks/events in one List showing the newest one first.
My code:
COMPONENT:
CONTROLLER:
APEX CONTROLLER
I have a component that shows results of task and event query in 2 seperated Lists. I want the combined results to be filtered by create date and be limited to 30 results.
So I see results of tasks/events in one List showing the newest one first.
My code:
COMPONENT:
<aura:component controller="ApexActivityWrapper" implements="force:appHostable,flexipage:availableForAllPageTypes,force:hasRecordId" access="global"> <aura:attribute name="TaskList" type="List"/> <aura:attribute name="EventList" type="List"/> <aura:handler name="init" value="{!this}" action="{!c.doInIt}"/> <p align="center" class="slds-text-heading_large ">Task List</p> <table class="slds-table slds-table_cell-buffer slds-table_bordered slds-table_striped"> <thead> <tr class="slds-line-height_reset"> <th class="" scope="col"> <div class="slds-truncate" > Task Subject </div> </th> </tr> </thead> <tbody> <tr class="slds-hint-parent"> <th data-label="" scope="row"> <div class="slds-truncate" > <aura:iteration items="{!v.TaskList}" var="task"> <p>{!task.Subject}</p><br/> </aura:iteration> </div> </th> </tr> </tbody> </table> <p align="center" class="slds-text-heading_large ">Event List</p> <table class="slds-table slds-table_cell-buffer slds-table_bordered slds-table_striped"> <thead> <tr class="slds-line-height_reset"> <th class="" scope="col"> <div class="slds-truncate" > Event Subject </div> </th> </tr> </thead> <tbody> <tr class="slds-hint-parent"> <th data-label="" scope="row"> <div class="slds-truncate" > <aura:iteration items="{!v.EventList}" var="event"> <p>{!event.Subject}</p><br/> </aura:iteration> </div> </th> </tr> </tbody> </table> <br/> <br/> </aura:component>
CONTROLLER:
({ doInIt : function(component, event, helper) { var action = component.get("c.method1"); action.setCallback(this, function(response){ var state = response.getState(); if(state === "SUCCESS") { var response = response.getReturnValue(); component.set("v.TaskList", response.taskList); component.set("v.EventList", response.eventList); } else if(state === "INCOMPLETE") { //do something } else if(state === "ERROR") { var error = response.getError(); if(error) { console.log("error"+errors); } } }); $A.enqueueAction(action); } })
APEX CONTROLLER
public class ApexActivityWrapper { @AuraEnabled public static wrapper method1 (){ string userId = UserInfo.getUserId(); List<Task> getTask = [SELECT Subject, ActivityDate FROM Task WHERE OwnerId=:userId ORDER BY ActivityDate]; List<Event> getEvent = [SELECT Subject, ActivityDate FROM Event WHERE OwnerId=:userId ORDER BY ActivityDate]; wrapper wrp = new wrapper(); wrp.taskList = new List<Task>(getTask); wrp.eventList = new List<Event>(getEvent); return wrp; } public class wrapper{ @AuraEnabled public List<Task> taskList ; @AuraEnabled public List <Event> eventList; } }