In regards to reports the regular ones are not working for what we are trying to achieve we have 5 objects that are related in someway or another but not specifically one to another, having an scenario like this
Object 1 has reference to 2 and 3
Object 2
Object 3
Object 4 has reference to 2
Object 5 has reference to 2
So in my initial query I can grab the needed info from Object 1, 2, 3 however since there is no connection from object 1,2 or 3 to objects 4 or 5 then I can't add them in the query or I don't know how to, now my questions is that once I pull the records I can run through them all and pull the needed related 4 and 5 object but how can I add that as part of the response, is there a way to create an array of objects or can I access objects 4,5 from the same query?
global static Object1__c[] getReport(Integer page, Id program){
Object1__c[] rows = [
select
Id,
Name,
/*Object2__r relations*/
o1.Object2__c,
o1.Object2__r.Name,
o1.Object2__r.Id,
/*Object2__r relations ends*/
/*Object3__r relations*/
o1.Object3__c,
o1.Object3__r.Name,
o1.Object3__r.Id,
/*Object3__r relations end*/
from Object1__c o1
where
o1.Program__c = :program
limit 30
];
if(rows.size() > 0){
for(Object1__c o1:rows){
/*query here the other two objects*/
Object4__c[] o4 = [
select
Id,
Name
from
Object4__c
where
Object1__c = :o1.Object2__r.Id
];
Object5__c[] o5 = [
select
Id,
Name
from
Object5__c
where
Object2__c = :o1.Object2__r.Id
];
/* how do I add o4 and o5 to the o1 row? */
}
}
return rows;
}