1

Does Salesforce Visualforce page have the ability to show table like this:

enter image description here

For example, the data is Map, where key is Employee and Value is List of reports.

Table should show which employees didn't fill report for last 3 months.

Report have Look up Field to Employee, and Month field.

CONTROLLER

podchinennie = false;

    lastMonths = new List<String>();
     lastYears = new List<Integer>();

    for (Integer i = 0; i < 3; i++) {
        String num = String.valueOf(Date.today().addMonths(-i).Month());
        if (num.length() == 1) num = '0' + num;
        lastMonths.add(num);
        if (!lastYears.contains(date.today().addMonths(-i).year())) {
            lastYears.add(date.today().addMonths(-i).year());
        }
    }

    lastMonths.sort();
    lastYears.sort();
    System.debug(lastMonths);
    System.debug(lastYears);

     mrlist = [
            select Id, Name,CreatedById,
                    TERF_MR_month__c, TERF_MR_year__c,
                    TERF_MR_EmployeeFullName__c, TERF_MR_EmployeeEmail__c, TERF_MR_Status__c
            from TERF_MR__c
            where CreatedById = :UserInfo.getUserId() OR TERF_MR_EmployeeEmail__c = :UserInfo.getUserEmail()
            order by CreatedDate desc
    ];
    empsReportList = [
            select Id, Name,
                    TERF_MR_month__c, TERF_MR_year__c,
                    TERF_MR_EmployeeFullName__c,
                    TERF_MR_EmployeeEmail__c,
                    TERF_MR_Status__c,
                    TERF_MR_EmployeeManagerEmail__c,
                    TERF_MR_monthNumber__c
            from TERF_MR__c
            where TERF_MR_EmployeeManagerEmail__c = :UserInfo.getUserEmail() AND TERF_MR_monthNumber__c IN:lastMonths AND TERF_MR_year__c IN:lastYears
            order by CreatedDate desc
    ];

    List<TERF_Employee__c> emps = [SELECT Name, TERF_EMP_Manager__r.TERF_EMP_Email__c  From TERF_Employee__c WHERE TERF_EMP_Manager__r.TERF_EMP_Email__c =: UserInfo.getUserEmail()];

    Set<String> employees = new Set<String>();
    if (!emps.isEmpty()) {
        for (TERF_Employee__c emp : emps) {
            employees.add(emp.Name);
        }
    }

    if (empsReportList.size() > 0 && employees.size() > 0) {
        empMap = new Map<String, Id[]>();
        for (TERF_MR__c mr : empsReportList) {
            for (String emp : employees) {
                if (mr.TERF_MR_EmployeeFullname__c == emp) {
                    if (empMap.keySet().contains(emp)) {
                        if (mr.TERF_MR_monthNumber__c == lastMonths[0]) {
                            empMap.get(emp)[0] = mr.Id;
                        } else if (mr.TERF_MR_monthNumber__c == lastMonths[1]) {
                            empMap.get(emp)[1] = mr.Id;
                        } else if (mr.TERF_MR_monthNumber__c == lastMonths[2]) {
                            empMap.get(emp)[2] = mr.Id;
                        }
                    } else {
                        Id[] arr = new Id[3];
                        if (mr.TERF_MR_monthNumber__c == lastMonths[0]) {
                            arr[0] = mr.Id;
                        } else if (mr.TERF_MR_monthNumber__c == lastMonths[1]) {
                            arr[1] = mr.Id;
                        } else if (mr.TERF_MR_monthNumber__c == lastMonths[2]) {
                            arr[2] = mr.Id;
                        }
                        empMap.put(emp, arr);
                    }
                }
            }
        }
        if (empMap.size() > 0) {
            podchinennie = true;
        }
    }
    for (String empString: employees) {
        if (!empMap.keySet().contains(empString)) {
            empMap.put(empString, new Id[3]);
        }
    }

VISUALFORCE

            <table class="interactiveTable" width="100%">
            <thead>
            <tr>
                <td> Employee / Month </td>
                <td>{!lastMonths[0]} </td>
                <td>{!lastMonths[1]}  </td>
                <td> {!lastMonths[2]} </td>
            </tr>
            </thead>

            <apex:repeat value="{!employees}" var="emp">
                <tr>
                    <td>{!emp}</td>
                    <td>{!empMap[emp][0]}</td>
                    <td>{!empMap[emp][1]}</td>
                    <td>{!empMap[emp][2]}</td>
                </tr>
            </apex:repeat>
        </table>

closed as unclear what you're asking by Jayant Das, Himanshu, glls, Oleksandr Berehovskyi, Derek F Oct 3 '18 at 17:59

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    A direct answer is "yes" - you can implement such a thing with Visualforce. Are you struggling with a specific issue here? Have you developed a design for this functionality? What are you looking for as an outcome for this question? – David Reed Oct 1 '18 at 13:59
  • Hi David! I'm look for code template to show empty cells. Also i can't imagine how to use apex:repeat exactly in this case. – Ivan S. Oct 1 '18 at 14:02
  • 5
    Just so you know, SFSE doesn't generally provide code for specific requirements. I'd encourage you to add details and show what you have tried to far to avoid seeing the question closed for being inspecific. Can you edit in some code to show how you're using <apex:repeat> and what's not working for you? – David Reed Oct 1 '18 at 14:28
  • David, i added controller and page code to question body. thank you for your replies! – Ivan S. Oct 1 '18 at 15:28
  • A description (possibly including screenshots) of what it does now, relative to what you want, could help. I've read through all this code and I think I understand most of what it does, but I don't see the specific problem that needs to be addressed. – David Reed Oct 2 '18 at 14:02