I want to create a list in order to use it in a vf page with the tag apex:pageblocktable. The schema below is just for learning purposes, it has 3 custom objects with look up relationships.
I had create the following queries but I think is far way from been efficient, specially the section were I am bringing the brand name as I loop through all the rows until i find an Id match.
string brandName;
string carType;
list<list<string>> Result = new list<list<string>>();
public list<list<string>> getResult(){
list<Model__c> cars1 = [SELECT Name, Brand__c, (Select Name FROM cars1__r) FROM Model__c];
list<Brand__c> brand = [SELECT Name,Country__c FROM Brand__c];
for (Model__c c:cars1 ){
for(Car__c details:c.cars1__r){
carType = details.name;
//GET THE BRAND OF THE CAR
for(Brand__c b:brand){
if (c.Brand__c == b.Id){
brandName = b.name;
}
}
//system.debug(brandName + ' ' + c.Name + ' ' + carType);
list<string> subresult = new List<string>();
subresult.add(brandName);
subresult.add(c.Name);
subresult.add(carType);
result.add(subresult);
}
}
return Result;
}
Also the problem is when I had my list, that is a group of lists inside the list I havent been able to find in the docs how to name each list, in order to use the apex tags to display in the vf page.