[SalesForce] How to Display Integer value got from SOQL Query (Apex Class) to Visualforce Page

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.

Best Answer

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?

Related Topic