2

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?

enter image description here

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!

8
  • The way you have prepared the list, same way loop through the <apex:repeat> and put <ul><li> properly to generate hierarchy Commented Apr 3, 2017 at 2:26
  • Strictly speaking, you could have done this all in one query without a wrapper at all.
    – sfdcfox
    Commented Apr 3, 2017 at 2:40
  • Do you mean @SantanuBoral , that I have something wrong when displaying it in the visualforce page?
    – JMRAF
    Commented Apr 3, 2017 at 2:40
  • How can I do it @sfdcfox ?
    – JMRAF
    Commented Apr 3, 2017 at 2:41
  • I'm having some challenge reading your code, but basically query the middle object, its parent fields, as necessary, and its related children as a subquery.
    – sfdcfox
    Commented Apr 3, 2017 at 2:49

0

You must log in to answer this question.

Browse other questions tagged .