0

I am having problems with the my visualforce page displaying the data from my SOQL query.

This is my controller:

public with sharing class fetchCaseCallsController {
private Id accountId;
public fetchCaseCallsController(ApexPages.StandardController sc) {
    accountId = sc.getId();
}

public Task[] getTasks() {
    if (accountId != null) {
        return [
                select Id, Subject
                from Task
                where WhatId in (select Id from Case where AccountId = :accountId)
                and Type = 'Call'
                ];
    } else {
        return new Task[] {};
    }


   }
}

Basically in the controller I am querying all calls that were made against a case for a specific account.

My VF page looks as follows:

       <apex:page standardController="Account" extensions="fetchCaseCallsController">

  <h1>Logged calls against cases</h1>
  <table>
  <apex:repeat value="{!tasks}" var="act">
    <tr>
      <td>This is the subject {!act.Subject}</td>
    </tr>
  </apex:repeat>
  </table>

</apex:page>

I don't really understand why nothing is displayed on my page? Tia.

2 Answers 2

2

The problem is that you have 2 get methods defined for the caseCalls list.

One as part of the {get;set;} on line 4 and another in the getCaseCalls() method.

The page is probably returning the result of the get; on line 4. But this caseCalls variable is never set.

Remove line 4 (and line 8 in which you initialize the empty list) and it will work.

The alternative is to remove the getCaseCalls() method and fill the caseCalls list in the fetchCaseCallsController method (instead of just creating an empty list there).

5
  • I have now edited my code (see above), but I still can't see anything in my VF page?
    – Lily
    Commented Nov 14, 2014 at 15:06
  • 1
    Did you check the debug logs to see whether the accountId is set and whether anything is returned in the SOQL query? Commented Nov 14, 2014 at 15:08
  • for some reason it does not fetch any rows, which is strange... can you see anything wrong with my query?
    – Lily
    Commented Nov 14, 2014 at 15:33
  • I just simplified my query and it does then fetch rows, so there must be something wrong with my SOQL statement. Basically I want the SOQL statement to fetch all the calls that were made against a case that is linked to a specific account. Tks
    – Lily
    Commented Nov 14, 2014 at 15:36
  • The query syntax isn't wrong (e.g. it returns data in my org). So it must be either the user authorizations (the user viewing the page can't see the tasks) or the filter on Type. Also check if the Account is actually filled in on the Cases that you want to be shown. Commented Nov 14, 2014 at 15:43
0

I believe there is no Type field on Task Object. If you have add a new custom field, change it into Type__c, then it should be works.

And instead of using repeat apex:repeat. I recommend you to use apex:pageBlockTable, because it's the official way to working with table in Visualforce.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .