I have a wrapper class inside a wrapper class which contains Assignment object and List of Projects.
public class projWrapper{
public Professional_Experience__c peWrap {get;set;}
public List<assignmentWrapper> assignmentListWrapper1 {get;set;}
}
public class assignmentWrapper{
public Assignment__c assignmentWrap1{get;set;}
public List<Project__c> projectforassignmentWrap {get;set;}
}
I want to show the certain Assignment/s within a Professional Experience and the certain Project/s within an Assignment. How can I achieve this?
Controller
I've made this code but when showing the result to the Visualforce page, it displays all the Assignments in every Professional Experience and all the Projects in every Assignment.
contactRecord = [SELECT Name, Email, HomePhone, MobilePhone FROM Contact WHERE ID =: thisContact.Id];
profExperienceList = [SELECT Id, Employee_ID__r.Name, Job_Title__c,Name,Start_Date__c,End_Date__c, STRING_Start_Date__c, STRING_End_Date__c, Job_Description__c, White_Label__c, (SELECT Company_Id__c, Name, White_Label__c, Description__c, Start_Date__c, End_Date__c, STRING_Start_Date__c, STRING_End_Date__c FROM Projects__r) FROM Professional_Experience__c WHERE Employee_ID__c =: contactRecord.Id ORDER BY Start_Date__c DESC LIMIT 3];
assignmentList = [SELECT Company_ID__c,End_Date__c,Name,Start_Date__c,Job_Title__c, STRING_Start_Date__c, STRING_End_Date__c FROM Assignment__c WHERE Company_ID__c IN : profExperienceList ORDER BY Start_Date__c DESC];
projectforassignmentList = [SELECT Name, Company_Id__c, Company_Id__r.Id, Company_Id__r.Name, Company_Id__r.Job_Description__c,Description__c, End_Date__c, Start_Date__c, White_Label__c, STRING_Start_Date__c, STRING_End_Date__c, Assignment_ID__c FROM Project__c WHERE Assignment_Id__c IN :assignmentList ORDER BY Start_Date__c DESC];
projListWrapper = new List<projWrapper>();
listofAssignmentWrapper = new List<assignmentWrapper>();
for(Professional_Experience__c profExperience : profExperienceList){
pw = new projWrapper();
List<Project__c> listofProjectforAssignment = new List<Project__c>();
for(Assignment__c assignment : assignmentList){
if(profExperience.Id == assignment.Company_ID__c){
alwra = new assignmentWrapper();
alwra.assignmentWrap1 = assignment;
for(Project__c projectforassignment : projectforassignmentList){
if(assignment.Id == projectforassignment.Assignment_ID__c){
listofProjectforAssignment.add(projectforassignment);
}
}
alwra.projectforassignmentWrap = listofProjectforAssignment;
listofAssignmentWrapper.add(alwra);
}
}
pw.peWrap = profExperience;
pw.assignmentListWrapper1 = listofAssignmentWrapper;
projListWrapper.add(pw);
}
Can anyone help me on how to achieve the picture above? Thanks!