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
Brian Cherry FWIBrian Cherry FWI 

Reformating Lists within Lists to create parent child

I am trying to create a List structure that contains this type of structure

Master Record Install
List of Related Project_Tasks to the Install
List of Related Users to the Project Task
List of Detail Records related to the Project Task.

This is related to being able to approve approval process instance ids. Since it's not really related, I'm having to try to build it backwards. Here's my code so far, I'm not sure who to get an SObject that has a List within a List within a List. Each List relates to one record within the the list.
public class JsonStructure
    {
        public SFDC_Project__c theInstall;
        public List<Project_Task__c> thePTs;
        public List<User> theUsers;
        public List<Details> detailList;
        
    
    }
    
   
    
    
    public class Details
    {
        public id theProcessId;
        public id TimeEntryId;
        public id Userid;
        public id InstallId;
        public string InstallName;
        public string Notes;
        public double Hours;
        public string UserName;
        public string TaskName;
        public string TaskId;
        public string theDate;
        public string reasonCode;
        public string theType;
        
        public Details()
        {
            
        }
    }
    public class PendingApproval{
         public final Id processId;
         public final Details Detail;
            public PendingApproval(Id processId, Details detail){
            this.processId = processId;
            this.detail = detail;
        }
    }
 
@remoteAction
    public static List<PendingApproval> getPendingApprovalsJson(){
                transient List<PendingApproval> pendingApprovals;
                List<ProcessInstanceWorkitem> unapprovedItems =
                [SELECT
                    ProcessInstanceId,
                    ProcessInstance.TargetObjectId
                 FROM ProcessInstanceWorkitem
                 WHERE ActorId = '00580000005ScLr'
                 AND ProcessInstance.TargetObject.Type = 'Time_Entry_Day__c'];
             Map<Id, ID> workItems = new Map<Id, ID>();
        for (ProcessInstanceWorkItem i : unapprovedItems)
        {
            workItems.put(i.ProcessInstance.TargetObjectId, i.ProcessInstanceId);
        }
        
        List<Time_Entry_Day__c> timeEntriesForApproval = new List<Time_Entry_Day__c>(
            [SELECT
                Id,
                User__c,
                User_Full_Name__c,
                Date__c,
                Install__c,
                Install_Name__c,
                Billable_Hours__c,
                Billable_Notes__c,
                Non_Billable_Hours__c,
                Non_Billable_Notes__c,
                Project_Task__c,
                Task_Name__c,
                Approved_Time__c,
			    Budgeted_Hours__c,
				Remaining_Time__c,
                Non_Bill_Reason_Code__c
             FROM Time_Entry_Day__c 
             WHERE Id IN :Pluck.ids('ProcessInstance.TargetObjectId', unapprovedItems)]);
        map<Id, Details> theDetails = new Map<id, Details>();
        list<SFDC_Project__c> installList = new List<SFDC_Project__c>();
        installList = [SELECT ID, SFDC_Project_Name__c from SFDC_Project__c where Id IN :Pluck.ids('Install__c', timeEntriesForApproval)];
        list<Project_Task__c> PTList = new List<Project_Task__c>();
        PTList = [SELECT ID, Approved_Billable_Time__c, Task__c from Project_Task__c where Id IN :Pluck.ids('project_task__c', timeEntriesForApproval)];
        List<User> userList = new List<User>();
        userList = [SELECT ID, Name from User where ID IN :Pluck.ids('User__c', timeEntriesForApproval)];

        
        
        
        
        for(Time_Entry_Day__c day :TimeEntriesForApproval)
        {
        Details d = new Details();
        d.theProcessId = workItems.get(day.id);    
        d.TimeEntryId = day.Id;    
        d.Userid = day.User__c;
        d.InstallId = day.Install__c;
        d.InstallName = day.Install_Name__c;
         if(day.Non_Billable_Notes__c != NULL || day.Non_Billable_Notes__c != '')
         {
         d.Notes = day.Non_Billable_Notes__c;  
         }
         else
         {
             d.Notes = day.Billable_Notes__c;
         }         
 
    
            if(day.Non_Billable_Hours__c == 0 || day.Non_Billable_Hours__c == NULL)
            {
        d.Hours = day.Billable_Hours__c;
        d.theType = 'Billable';        
            }
            else
            {
            d.Hours = day.Non_Billable_Hours__c;
            d.theType = 'Non-billable';    
            }
        d.reasonCode =  day.Non_Bill_Reason_Code__c;  
        d.UserName = day.User_Full_Name__c;
        d.TaskName = day.Task_Name__c;
        d.TaskId = day.Project_Task__c;
        d.theDate = day.Date__c.format();
        thedetails.put(d.TimeEntryId, d);
        }
        pendingApprovals = new List<PendingApproval>();
        for(ProcessInstanceWorkitem workItem : unapprovedItems){
            pendingApprovals.add(new PendingApproval(workItem.Id, theDetails.get(workItem.ProcessInstance.TargetObjectId)));
        }
        return pendingApprovals;
    }