You need to sign in to do that
Don't have an account?
Diane Carroll
Help with custom controller?
Hello- I'm hoping for some help with a visualforce page. I can't seem to find the answers in the documentation.
What I need to do is diplay a specific subset of cases on a public visualforce page. I need to be able to include the comments as well. I can successfully display cases but can't quite get it to the point where it only displays the ones I need. (specific record type and 2 types)
For some reason the code (as shown at the bottom) shows right across the bottom of the screen and I just can't figure out how to add the comments in a column too. I've tried creating a custom controller, but my apex fell short of success.
Code:
<apex:page id="GraniteChangeLog2" standardController="Case" recordSetvar="cases" sidebar="false" showHeader="false" standardStylesheets="true">
<body style="background-image:url('{!$Resource.Logo}');" />
<apex:define name="head">
<title>Granite State College-Change Log v2</title>
</apex:define>
<apex:define name="content">
<apex:variable var="width" value="850"/>
<apex:variable var="border" value="0"/>
<apex:variable var="cellspacing" value="0"/>
<apex:variable var="cellpadding" value="5"/>
<apex:form >
<apex:pageBlock >
<b><h1>Change Management Cases</h1></b>
<apex:pageBlockTable value="{!cases}" var="c">
<apex:column value="{!c.casenumber}"/>
<apex:column value="{!c.CreatedDate}"/>
<apex:column value="{!c.status}"/>
<apex:column value="{!c.subject}"/>
<apex:column value="{!c.type}"/>
<apex:column value="{!c.BusinessCase__c}"/>
<apex:column value="{!c.RiskAssesment__c}"/>
<apex:column value="{!c.RollbackPlan__c}"/>
<apex:column value="{!c.TestPlan__c}"/>
<apex:column value="{!c.IsClosed}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:define>
public class retrieveCase {
public List getCases() {
return [SELECT status, subject FROM Case
WHERE RecordTypeID='012M0000000D62J' AND status != 'Closed' limit 5];
}
</apex:page>
Thank you.
What I need to do is diplay a specific subset of cases on a public visualforce page. I need to be able to include the comments as well. I can successfully display cases but can't quite get it to the point where it only displays the ones I need. (specific record type and 2 types)
For some reason the code (as shown at the bottom) shows right across the bottom of the screen and I just can't figure out how to add the comments in a column too. I've tried creating a custom controller, but my apex fell short of success.
Code:
<apex:page id="GraniteChangeLog2" standardController="Case" recordSetvar="cases" sidebar="false" showHeader="false" standardStylesheets="true">
<body style="background-image:url('{!$Resource.Logo}');" />
<apex:define name="head">
<title>Granite State College-Change Log v2</title>
</apex:define>
<apex:define name="content">
<apex:variable var="width" value="850"/>
<apex:variable var="border" value="0"/>
<apex:variable var="cellspacing" value="0"/>
<apex:variable var="cellpadding" value="5"/>
<apex:form >
<apex:pageBlock >
<b><h1>Change Management Cases</h1></b>
<apex:pageBlockTable value="{!cases}" var="c">
<apex:column value="{!c.casenumber}"/>
<apex:column value="{!c.CreatedDate}"/>
<apex:column value="{!c.status}"/>
<apex:column value="{!c.subject}"/>
<apex:column value="{!c.type}"/>
<apex:column value="{!c.BusinessCase__c}"/>
<apex:column value="{!c.RiskAssesment__c}"/>
<apex:column value="{!c.RollbackPlan__c}"/>
<apex:column value="{!c.TestPlan__c}"/>
<apex:column value="{!c.IsClosed}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:define>
public class retrieveCase {
public List getCases() {
return [SELECT status, subject FROM Case
WHERE RecordTypeID='012M0000000D62J' AND status != 'Closed' limit 5];
}
</apex:page>
Thank you.
The apex page also needs to either implement that new apex class as an extension or you can drop the standard case controller for a custom controller. Depending on the path you choose your retrieveCase class would need appropriate changes.
Hopefully that points you in the right direction. Refer to the documentation section on extensions and custom controllers.
- You can either use a subquery [1] and select the comments associated with your case, and add them to the layout.
- You can take all of you cases and make a seperate query that gets the comments, stores them in a map of Case Id => List of Comments and then using a new method return that list to be displayed. If you go with this route, I would suggest that you move your case query to the constructor of you class and store it in a class level variable. That way it will only be called once and you can use getCases multiple times without hitting any DML limits.
If you need more explaination of either of these two methods, please let me know.NOTE: Please use the "Add a code sample" button (icon of <>) to increase readability
[1] http://www.salesforce.com/us/developer/docs/dbcom_soql_sosl/Content/sforce_api_calls_soql_relationships.htm
I cannot find an answer in the thousands of pages of documentation and postings.
Perhaps I'm asking my question incorrectly so... please point me in the right direction..I need either to find out where to include this code to use the standard controller for cases OR the correct syntax to list the columns with a custom controller. Every sample I have found shows it exactly this way: but when I try this same method with my custom controller I get an error message saying "Unknown property 'String.casenumber'"
Thank you.
NOTE: This code has not been tested and may contain typographical or logical errors
Then you should be able to use your VisualForce like that. Since you were just returning a string, you cannot get the object information.
In the code above I'm doing some lazy loading [1] of the cases so that if you don't change the select option (that you would store in the recordType variable) it will only query a single time. You will need to do some selective page reloading [2] in your VisualForce for when you change the RecordType select list, but that's a different issue all together.
[1] http://blog.deadlypenguin.com/blog/2012/04/04/reducing-salesforce-soql-queries-by-using-static-variables/
[2] http://blog.deadlypenguin.com/blog/2012/07/09/dynamic-dependent-picklists-in-salesforce/