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
Salvatore GomezSalvatore Gomez 

Return results of two soql queries into a single blocktable row

Hello all,
 I'm trying to retrieve the latest attachment from Job_Applicants__c and the latest attachment from from Applied_Applicants__c and combine into a single blocktable row. The requirement i'm trying to achieve is that a job applicant can attach a resume to their account record but they need to attach a customized cover letter for each job they apply to. So far i'm just tampering around with soql code so any suggestions are very much appreciated.

  Records = [Select Name,First_Name__c,Last_Name__c, (Select Id, LastModifiedDate From Attachments Order By LastModifiedDate DESC)
                 From Job_Applicants__c t where Id in (select Applicant__c from Applied_Applicants__c where JobPosting__c=:A and Status__c not in    ('Offered','Taken'))];

   Applicants =[Select Id, (Select Id, LastModifiedDate From Attachments Order By LastModifiedDate DESC)
                   from Applied_Applicants__c where JobPosting__c=:A and Status__c not in ('Offered','Taken')];
Michael DsozaMichael Dsoza
Hi Salvatore,

Go with MAP<key, WrapperClass> & iterate the map to get the desired output.
for more information about wrapper class, https://developer.salesforce.com/page/Wrapper_Class

Hope it will help you.
Mark it as best answer if it resolves your query.

Thanks
Salvatore GomezSalvatore Gomez
Thanks for pointing me in the right direction, i'm currently testing this idea out. Right now my issue seems to be that i can't return the id of an attachment in the following code. I'm struggling with returning the attachment from Job_Applicants__c since it's a join within objAs.  Any thoughts on how to retireve the attachment Id?

public with sharing class YourVFPageController {

 
    public Map<Id, SalesRepWrapper> salesRepWrappersMap { get; set; }

    public YourVFPageController() {

        salesRepWrappersMap = new Map<Id, SalesRepWrapper>();

        List<Job_Applicants__c> objAs = [Select t.Id, t.Name,t.First_Name__c,t.Last_Name__c,
                (Select A.Id, A.LastModifiedDate
                 From Attachments A
                 Order By LastModifiedDate DESC)
                 From Job_Applicants__c t
                  where Id in (select Applicant__c from Applied_Applicants__c where Status__c not in ('Offered','Taken'))];
        
     
        List<Applied_Applicants__c> objBs = [Select Applicant__c,
                (Select Id, LastModifiedDate
                 From Attachments
                 Order By LastModifiedDate DESC)
                 From Applied_Applicants__c
                 where Status__c not in ('Offered','Taken')];

        for(Job_Applicants__c objA : objAs) {
            if (salesRepWrappersMap.containsKey(objA.Id)) {
                salesRepWrappersMap.get(objA.Id).revenue = objA.Name;
                
                
                 
            } else {
                salesRepWrappersMap.put(objA.Id, new SalesRepWrapper(objA));
            }
        }

        for(Applied_Applicants__c objB : objBs) {
            if (salesRepWrappersMap.containsKey(objB.Applicant__c)) {
                salesRepWrappersMap.get(objB.Applicant__c).goals = objB.Id;
            } else {
                salesRepWrappersMap.put(objB.Applicant__c, new SalesRepWrapper(objB));
            }
        }
    }
    
    public class SalesRepWrapper {
    public String salesRep { get; set; }
    public String revenue { get; set; }
    public String goals { get; set; }
    public String resume {get; set;}

    public SalesRepWrapper(Job_Applicants__c objA) {
        this.salesRep = objA.Id;
        this.revenue = objA.First_Name__c;
     
        
    }

    public SalesRepWrapper(Applied_Applicants__c objB) {
        this.salesRep = objB.Applicant__c;
        this.goals = objB.Id;
    }
    

}
}