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
DekorDekor 

Viewing list of open cases from account page

At present when I want to view all open cases against an account in salesforce I go to the account in question, then from the cases related list I click "view all" then order by status column.  This is a bit cumbersome and I'm hoping I can develop something to simplify this.  I was thinking of creating a custom button on the account detail page called "Open cases" that will take me to a list of cases. 

Imagine this would be best done with a visual force page and the button would link to this page/automatically provide the account ID for filtering.  

Has anyone created anything similar to this and have any tips I could look at?  Would I need to create a custom controller for this task?
Best Answer chosen by Dekor
Rajiv Penagonda 12Rajiv Penagonda 12
Dekor, I see your point. You could go with inline VF page as Venky above has suggested. In which case you could also avoid the additional step of clicking the button (and going away from account page).

Your open cases can be neately paginated and rendered within your account page layout as a related list. Below is a link that might help your with this:

http://salesforcesource.blogspot.in/2008/10/how-to-create-custom-related-list-on.html

All Answers

Rajiv Penagonda 12Rajiv Penagonda 12
Is there any reason why you have not considered a report for this? Custom code just to handle this seems a little overkill.
DekorDekor
Why would I want to have to create a report everytime I want to see a list of cases against an account/modify the filter on a precreated report?  Especially as if you want to filter on account name you need to enter it in identically to what is against the account record (using contains could include multiple sites if you have accounts containing similar words) so you would need to look up the account anyway before creating/modifying your report.

Creating a VF page once that could accept the account ID filter from the action button would be a lot more suitable wouldn't you agree?

So user goes to account details page of account in question, presses button, is presented with list of open cases.  Its a one time development, add button to account page layout and then gives you access to do this on all accounts. 
venkat-Dvenkat-D
if the requiremetn is just to display list with a link to case on account, i would suggest adding an inline visualforce page in account layout itself. That way you have data on account view.
Rajiv Penagonda 12Rajiv Penagonda 12
Dekor, I see your point. You could go with inline VF page as Venky above has suggested. In which case you could also avoid the additional step of clicking the button (and going away from account page).

Your open cases can be neately paginated and rendered within your account page layout as a related list. Below is a link that might help your with this:

http://salesforcesource.blogspot.in/2008/10/how-to-create-custom-related-list-on.html
This was selected as the best answer
DekorDekor
Thank you for the advice, I'm having a read through and trying to see how I would use this in an account/case relationship setting.  Will I need to create a custom controller for this page?
Rajiv Penagonda 12Rajiv Penagonda 12
Yes, a custom controller will be needed as the Case information cannot be accessed through the Standard Controller alone. Also, you may have to use a filter criteria (like all open cases only etc) and pagination through standard set controller, which cannot be done without a dedicated controller.
DekorDekor
Ok, so I have created my visualforce page:
 
<apex:page standardController="Account" extensions="OpenCases">
<style>
.fewerMore { display: none;}
</style>
<apex:form >
 <apex:pageMessages />
 <apex:detail relatedList="true"></apex:detail>
<apex:pageblock id="CustomList" title="Related Cases"  >
   <apex:pageBlockTable value="{!cse}" var="c" rendered="{!NOT(ISNULL(cse))}">
        <apex:column value="{!c.CaseNumber}"/>
        <apex:column value="{!c.Account.Name}"/>
        <apex:column value="{!c.Type}"/>
   </apex:pageBlockTable>
   <apex:outputLabel value="No records to display" rendered="{!(ISNULL(cse))}" styleClass="noRowsHeader"></apex:outputLabel>
 </apex:pageblock>
</apex:form>
</apex:page>
As well as a custom controller for querying the cases/filtering on account ID and if closed = false:
 
public class OpenCases {
    private List<Case> cse;
    private Account acnt; 
    public OpenCases(ApexPages.StandardController controller) {
        this.acnt= (Account)controller.getRecord();
    }
    public List<Case> getcse()
    {
        Account acc = [Select id FROM Account where id = :acnt.id];
        if (acc.id == null)
         return null;
        cse = [Select CaseNumber, Type from case where Case.Account.id = :acc.id and Case.isclosed = False];
        return cse;
    }
}

So i've now added the visual force page to my account page layout but its returning this error.  Any thoughts?

Content cannot be displayed: SObject row was retrieved via SOQL without querying the requested field: Case.Account
 
DekorDekor
Ah, ok well fixed this error, I had forgot to include case.account.name in the query on the class.

However if I add the visual force page to the account layout screen it just displays a clone of "account detail" rather than a list of cases.  So instead I've added a custom button with URL modified to provide account ID to the visual force page.  I now get a the ist of open cases and I've tested to ensure its only showing open cases for the account in question which is great.

Only thing I'd like to know is how to add links to this list, so users can click on the case number and it will take them to the case for example?

Here is screenshot of the list.

User-added image
DekorDekor
Here is a screenshot of the attempt at inline, no idea what happened here!

User-added image
Rajiv Penagonda 12Rajiv Penagonda 12
You can update your VF page as follows and the Case Number should come as a link:
 
<apex:page standardController="Account" extensions="OpenCases">
	<style>
		.fewerMore { display: none;}
	</style>
	<apex:form >
	<apex:pageMessages />
	<apex:detail relatedList="true"></apex:detail>
		<apex:pageblock id="CustomList" title="Related Cases"  >
			<apex:pageBlockTable value="{!cse}" var="c" rendered="{!NOT(ISNULL(cse))}">
				<apex:column headerValue="Case Number" >
					<apex:outputLink value="/{!c.id}">{!c.CaseNumber}</apex:outputLink>
				</apex:column>
				<apex:column value="{!c.Account.Name}"/>
				<apex:column value="{!c.Type}"/>
			</apex:pageBlockTable>
			<apex:outputLabel value="No records to display" rendered="{!(ISNULL(cse))}" styleClass="noRowsHeader"></apex:outputLabel>
		</apex:pageblock>
	</apex:form>
</apex:page>
Rajiv Penagonda 12Rajiv Penagonda 12
Also, if you want the link to open in a new tab, do this to the outputlink:

<apex:outputLink target="_blank" value="/{!c.id}">{!c.CaseNumber}</apex:outputLink>