I am new to Apex and trying to access the value from Custom Controller having SOQL query and show it on visualforce page as an Output link.

Visualforce snippet:

<div class="count"><apex:outputText value="{!Record}"/></div>

Apex Code Snippet:

public Integer getDisplayQueryList() {
        Records = 0;
        Records = [select count() from Case where Type like 'MDD Increase from WSC']; 
        return Records;

Also I have read about the AggregateResult[] which might be the best way to use but not sure how to use it properly. My main aim is to search & Count for all Cases which are NOT Closed & of Type = MDD Increase from WSC and then display that count in the visual force page.

Any Help would be much appreciated.

2 Answers 2


In your VF page use this

<div class="count"><apex:outputText value="{!DisplayQueryList}"/></div>

adding get automatically makes the method available in VF. You can call it in VF without using get keyword. You can display it in OutputLink or any VF component of your choice.

Infact you don't need to use aggregate result for this basic example. For complex SOQL having Group by etc needs aggregate query results object.

Welcome to Salesforce StackExchange. Happy coding.

You can checkout the extra resources to get deeper idea into VF and SOQL.

Apex Controllers: What do the get; set; do?

  • Thanks a lot Pranay Jaiswal. It is working fine now. Not sure what I was doing wrong. I thought the method name is getQueryList and not just QueryList so I tried accessing that but it didn't work.
    – AMAN
    Commented Jul 14, 2016 at 11:08
  • Happy To help :) Commented Jul 14, 2016 at 11:09

Use below code

    public Integer getDisplayQueryList() {

    List<AggregateResult> aggrs = Database,query('select count() cnt from Case where Type like 'MDD Increase from WSC');

    AggregateResult aggr = aggrs.get(0);

    return (Integer)aggr.get('cnt');

In VF page use below code:

<div class="count"><apex:outputLink value="/{!DisplayQueryList}"> {!DisplayQueryList}</apex:outputLink></div>

Hope it helps you. For more details on output link use below link:


You must log in to answer this question.

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