+ Start a Discussion
Josip KrajnovićJosip Krajnović 

visualforce display HTML table when list has no values

I have 3 custom objects with a Master-Detail Relationship and Lookup Relationship.
CustomA__c (related CustomB__c) <-> CustomB__c <-> CustomC_c (related CustomB_cc)

I´ve built a Visualforce page with HTML table to replicate a PDF document and a Custom Controller Extension, so far so good.
But I´m just a beginner with apex coding.

The problem is that I need to replicate the document as it is, when there are no related records for CustomA__c or less then 5, it should still show the full table (the empty rows). Max. rows/related records on the document is 5, no second page needed.

Currently I´m trying to accomplisch that by using apex:variable and apex:repeat as I´ve seen some examples, but perhaps there is also another solution. For the Visualforce page I already wrote the code for the rows with data and another apeax:repeat for the empty rows.

But I´m really strugling with the controller, i know i need to iterate over the list, the code that i already wrote is also put together out of examples as i just don´t understand it yet good enough.

public with sharing class CustomAController {    
    public CustomA__c customa{get; set;}
    public CustomA__c ca{get; set;}
    public CustomAController (ApexPages.StandardController controller) {
        ca = (CustomA__c )controller.getRecord();
        customa= [SELECT Id, Name  FROM CustomA__c WHERE Id = :ApexPages.currentPage().getParameters().get('Id')];
        public List<CustomB__c > getrelatedCustomB() {
        List <CustomB__c > cbList = New List<CustomB__c >(5);
        for(CustomA__c acc:[SELECT Id, Name, (SELECT Id, Name, ... , CustomCfield__r.Name FROM CustomBs__r ORDER BY Name LIMIT 5) FROM CustomA__c WHERE Id = :customa.Id]){
            for(CustomB__c cb:acc.CustomBs__r)
        return cbList;