function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jonathan Wolff 7Jonathan Wolff 7 

Display fields from two different objects in a single column of a datatable?

Hello, so I try to create a datatable component that displays tasks and events of a contact in a single table. 
task1   ActivityDate
task2   ActivityDate
event1   ActivityDate
task3   ActivityDate
event2   ActivityDate
event3   ActivityDate

For now I created a code that shows both tasks and events but in two seperated areas, but I really do not know what approach I should take to combine the results of these two. Maybe you could help me with this topic. So my Controller now is like that:
 
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;
	}
}

 
Naveen KNNaveen KN
one way is to create a wrapper class with a similar set of fields from the event and task objects. Iterate through a list of events and tasks and add the items to the wrapper. 

Find a detailed example in this link How to display multiple object records in a single lightning data table of Salesforce (https://www.codekiat.com/2022/11/display-multiple-object-records-in-single-lightning-data-table-salesforce.html)