- Display the custom list view of case object using visualforce page and custom controller.
- Here <apex:pageMessages/>' tag is used to show message on page when no case founds in object. And to display message, code is written in else block in constructor.
Visualforce Page:
<apex:page controller="CaseList" sidebar="false">
<apex:pageMessages/>
<apex:pageBlock>
<apex:pageBlockTable value="{!lstCase}" var="c">
<apex:column width="20px">
<apex:facet name="header">Case Number</apex:facet>
<apex:outputText value="{!c.CaseNumber}"/>
</apex:column>
<apex:column width="20px">
<apex:facet name="header">Account Name</apex:facet>
<apex:outputText value="{!c.Account.Name}"/>
</apex:column>
<apex:column width="20px">
<apex:facet name="header">Contact Name</apex:facet>
<apex:outputText value="{!c.Contact.Name}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>
Apex Class(Controller) :
public class CaseList
{
public List<Case> lstCase{get;set;}
public CaseList()
{
List<Case> caseList = [SELECT Id,CaseNumber,Account.Name,Contact.Name FROM Case order by createddate desc];
if(caseList!=null && caseList.size()>0)
{
lstCase=caseList;
}
else
{
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'No Case found.');
ApexPages.addMessage(myMsg);
}
}
}
0 comments:
Post a Comment
If you have any doubts, please let me know.