function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MVJMVJ 

Custom Controller for cases

I have created a custome VF page to display a summary of cases for a specific account.
 
I have a custom controller and evrything is wroking just fine except I can not find a way to get the Case Owner name.
 
Since cases can be owned by either a Queu or a user how do I return the name to display that in my VF page.
 
The page and controller are below for refrence.
 
How do I get the Owner Name?
 
Here is the VF Page:
 
Code:
<apex:page Controller="CaseController" tabstyle="Account">
    
    <apex:pageBlock title="Account">
    <apex:pageBlockSection title="Account Detail" columns="2" collapsible="true">
        <apex:outputField value="{!Account.Name}" id="AccountName"></apex:OutputField>
        <apex:pageBlockSectionItem>
            <apex:outputLabel value="Account Owner" for="AccountOwner"></apex:outputLabel>
            <apex:outputField value="{!Account.Owner.name}" id="AccountOwner"></apex:OutputField>
        </apex:pageBlockSectionItem>
        <apex:outputField value="{!Account.Site}"></apex:OutputField><apex:outputText></apex:outputText>
        <apex:outputField value="{!Account.BillingStreet}"></apex:OutputField><apex:outputText></apex:outputText>
        <apex:outputField value="{!Account.BillingCity}"></apex:OutputField><apex:outputText></apex:outputText>
        <apex:outputField value="{!Account.BillingState}"></apex:OutputField><apex:outputText></apex:outputText>
        <apex:outputField value="{!Account.BillingPostalCode}"></apex:OutputField><apex:outputText></apex:outputText>
    </apex:pageBlockSection>
    </apex:pageBlock>
        
    <apex:pageBlock title="Summary of cases">
    <table class="list" border="0" cellspacing="0" cellpadding="0">
    <tr class="headerRow"><th scope="col" class=""></th><th scope="col" class="">Total Number<br>Cases</br></th><th scope="col" class="">Cases<br></br>Open to date</th><th scope="col" class="">Cases<br></br>This Week</th><th scope="col" class="">Last Case Opened<br></br>Request #</th><th scope="col" class=""><br></br>Date Opened</th><th scope="col" class=""><br></br>Description</th></tr>
    <tr><td scope="col">Service</td><td scope="col" class="">{!ServiceCount}</td><td scope="col" class="">{!ServiceCountOpen}</td><td scope="col" class="">{!ServiceCountOpenThisWeek}</td><td scope="col" class=""><a href="/{!LastOpenServiceCase.Id}">{!LastOpenServiceCase.CaseNumber}</a></td><td scope="col" class="">{!LastOpenServiceCase.CreatedDate}</td><td scope="col" class="">{!LastOpenServiceCase.subject}</td></tr>
    <tr><td scope="col">Project</td><td scope="col" class="">{!ProjectCount}</td><td scope="col" class="">{!ProjectCountOpen}</td><td scope="col" class="">{!ProjectCountOpenThisWeek}</td><td scope="col" class=""><a href="/{!LastOpenProjectCase.Id}">{!LastOpenProjectCase.CaseNumber}</a></td><td scope="col" class="">{!LastOpenProjectCase.CreatedDate}</td><td scope="col" class="">{!LastOpenProjectCase.subject}</td></tr>
    </table>
    </apex:pageBlock>


    <apex:pageBlock title="Service / Project Cases" >
    <apex:pageBlockSection title="Open Service Requests" columns="1" collapsible="true">
    <apex:dataTable value="{!ServiceCases}" var="each" cellpadding="10" border="0" styleClass="list">
        <apex:column headerValue="Action"><a href="/{!each.Id}/e—retURL=/apex/CaseSummaryView–Id={!account.Id}"><b>Edit</b></a><b>&nbsp;|&nbsp;</b><a href="/{!each.Id}/s˜retURL=/apex/CaseSummaryView™Id={!account.Id}"><b>Cls</b></a> </apex:column>
        <apex:column headerValue="Case"><a href="/{!each.Id}">{!each.CaseNumber}</a></apex:column>  
        <apex:column headerValue="Contact Name">{!each.Contact.Name}</apex:column>  
        <apex:column headerValue="Subject">{!each.subject}</apex:column>  
        <apex:column headerValue="Priority">{!each.Priority}</apex:column>
        <apex:column headerValue="Status">{!each.Status}</apex:column>
        <apex:column headerValue="OwnerId">{!each.OwnerId}</apex:column>
    </apex:dataTable>
    </apex:pageBlockSection>

    <apex:pageBlockSection title="Open Timekeeper Projects" columns="1" collapsible="true">
    <apex:dataTable value="{!ProjectCases}" var="each" cellpadding="10" border="0" styleClass="list">
        <apex:column headerValue="Action"><a href="/{!each.Id}/e?retURL=/apex/CaseSummaryView?Id={!account.Id}"><b>Edit</b></a><b>&nbsp;|&nbsp;</b><a href="/{!each.Id}/s?retURL=/apex/CaseSummaryView?Id={!account.Id}"><b>Cls</b></a> </apex:column>
        <apex:column headerValue="Case"><a href="/{!each.Id}">{!each.CaseNumber}</a></apex:column>  
        <apex:column headerValue="Contact Name">{!each.Contact.Name}</apex:column>  
        <apex:column headerValue="Subject">{!each.subject}</apex:column>  
        <apex:column headerValue="Priority">{!each.Priority}</apex:column>
        <apex:column headerValue="Status">{!each.Status}</apex:column>
        <apex:column headerValue="OwnerId">{!each.OwnerId}</apex:column>
    </apex:dataTable>
    </apex:pageBlockSection>
    </apex:pageBlock>
    
    <apex:pageBlock title="Customer Service Center Cases" >
        <apex:pageBlockSection title="Service Cases" columns="1" collapsible="true">
        </apex:pageBlockSection>

        <apex:pageBlockSection title="Adjustment Cases" columns="1" collapsible="true">
        </apex:pageBlockSection>
        
        <apex:pageBlockSection title="Trouble Tickets" columns="1" collapsible="true">
        </apex:pageBlockSection>
        
        <apex:pageBlockSection title="Orders" columns="1" collapsible="true">
        </apex:pageBlockSection>

    </apex:pageBlock>

</apex:page>

 
Here is the Controller:
Code:
public class CaseController{
//** Service Request Functions
        Public Integer getServiceCount(){
                return [Select Count() from Case where AccountId= :System.currentPageReference().getParameters().get('id')and RecordType.Name = 'Service Request'];
        }
        Public Integer getServiceCountOpen(){
                return [Select Count() from Case where AccountId= :System.currentPageReference().getParameters().get('id') and isClosed = false and RecordType.Name = 'Service Request' ];

        }
        Public Integer getServiceCountOpenThisWeek(){
                return [Select Count() from Case where AccountId= :System.currentPageReference().getParameters().get('id') and isClosed = false and CreatedDate = THIS_WEEK and RecordType.Name = 'Service Request'];

        }
        Public Case getLastOpenServiceCase(){
                return [Select Id, CaseNumber, Subject, CreatedDate from Case where AccountId= :System.currentPageReference().getParameters().get('id') and isClosed = false and RecordType.Name = 'Service Request' Order By CreatedDate desc limit 1];
        }

        Public Case[] getServiceCases(){
                return [Select id, CaseNumber, ContactId, Contact.Name, OwnerId, Priority, Status, Subject from Case where accountid = :System.currentPageReference().getParameters().get('id') and isclosed = false and RecordType.Name = 'Service Request'];
        }

//** TimeKeeper Project Functions
        Public Integer getProjectCount(){
                return [Select Count() from Case where AccountId= :System.currentPageReference().getParameters().get('id')and RecordType.Name = 'TimeKeeper Project'];
        }
        Public Integer getProjectCountOpen(){
                return [Select Count() from Case where AccountId= :System.currentPageReference().getParameters().get('id') and isClosed = false and RecordType.Name = 'Timekeeper Project' ];

        }
        Public Integer getProjectCountOpenThisWeek(){
                return [Select Count() from Case where AccountId= :System.currentPageReference().getParameters().get('id') and isClosed = false and CreatedDate = THIS_WEEK and RecordType.Name = 'Timekeeper Project'];

        }
        Public Case getLastOpenProjectCase(){
                return [Select Id, CaseNumber, Subject, CreatedDate from Case where AccountId= :System.currentPageReference().getParameters().get('id') and isClosed = false and RecordType.Name = 'Timekeeper Project' Order By CreatedDate desc limit 1];
        }

        Public Case[] getProjectCases(){
                return [Select id, CaseNumber, ContactId, Contact.Name, OwnerId, Priority, Status, Subject from Case where accountid = :System.currentPageReference().getParameters().get('id') and isClosed = false and RecordType.Name = 'Timekeeper Project'];
        }
        
//** Other functions
        Public Account getAccount(){
                //return [Select id, name from Account where id = :System.currentPageReference().getParameters().get('id')];
                return [Select id, name, Owner.Name, Site, BillingStreet, BillingCity, BillingState, BillingPostalCode
                        from Account where id = :System.currentPageReference().getParameters().get('id')];

        }
        
        Public Case[] getAccountCases(){
                return [Select id, CaseNumber, ContactId, Contact.Name, OwnerId, Priority, Status, Subject from Case where accountid = :System.currentPageReference().getParameters().get('id')];
        }

}

 
MVJMVJ
I am close.  I figures out how I can create another getter function to retrieve the user name.

But how do I pass a variable to the getter so it knows what user to pull?

I want this to be in the repeat function where I am currently displaying the OwnerId.

Any thoughts?


MVJMVJ
This has been resolved. 

You can use Owner.Name in the SOQL statement and SFDC will pull back the correct user name regardless of if it is a users or Queue.