You need to sign in to do that
Don't have an account?
di_zou
How do I get a “New” button on my custom apex:pageBlockTable for Cases?
I have a custom Cases apex page where I use a apex:pageBlockTable to display my list of Cases. Here is the code for it:
<apex:page standardController="Case" recordSetVar="Case" sidebar="true" showHeader="true"> <apex:form > <apex:pageBlock title="Cases"> <apex:outputLabel value="View:"/> <apex:selectList value="{!filterId}" size="1"> <apex:actionSupport event="onchange" rerender="cases_table"/> <apex:selectOptions value="{!listviewoptions}"/> </apex:selectList> <apex:pageBlock > <apex:pageBlockButtons > </apex:pageBlockButtons> <apex:pageBlockTable value="{!case}" var="c" rows="50" id="cases_table" > <apex:column > <a target="_parent" href="{!URLFOR($Action.Case.View, c.id)}">{!c.CaseNumber}</a> <apex:facet name="header">Case Number</apex:facet> </apex:column> <apex:column value="{!c.ContactId}" /> <apex:column value="{!c.Subject}" /> <apex:column value="{!c.Status}" /> <apex:column value="{!c.Priority}" /> </apex:pageBlockTable> </apex:pageBlock> </apex:pageBlock> </apex:form> <base target="_parent"/> </apex:page>
I would like to get a button inside my apex:pageBlockButtons like in the default Cases page. When the user clicks the button, I would like it to take the user to the new Cases page. I tried this:
<apex:commandButton action="{!new}" value="New"/>
but that gave me an error. How do I make a button that will take me to the new Cases page?
According to this post, you need to modify it.... http://boards.developerforce.com/t5/General-Development/Output-Link-to-create-a-new-Case/td-p/274935
All Answers
You're supposed to contain pageBlockButtons in a single un-nested pageBlock instance.
I don't believe there is a way to create buttons for a table header using Visualforce.
I can create this without any errors:
I'm looking for a way to get a "New" button instead of a "Save" button.
When I do that however, I get this error:
Error: action="{!new}": Unknown method 'CaseStandardController.new()'
The code I posted was purely an example of how you should be writing your code.
New is not a method you have written, nor is a standard method. You will need to write some Apex code to ensure that button works.
Create a method in your Apex Class and call it new(). You will then be able to save your page.
Looks like you'll have to make an extension class...
There's currently no method for a "new" record according to the docs... http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_std_actions.htm
What you can do if you want to redirect them to create a 'new' record is do something like the following within your extension class
A better way of doing is to leave Apex out of it and use URLFOR() within your Visualforce tag to send the user to the page.
Something like this should work:
When I do:
I get this error:
Error: Field $Action.Case.New does not exist. Check spelling
Where can I find what methods are in $Action.Case?
According to this post, you need to modify it.... http://boards.developerforce.com/t5/General-Development/Output-Link-to-create-a-new-Case/td-p/274935
Awesome, thank you!
That is just frustrating... well done on the find.
It was really frustrating that I cound't find a list of those functions for the Case. It's also really frustrating that the function would be different for different models.
Why couldn't they keep:
"{!URLFOR($Action.Account.New)}"
the same for cases:
"{!URLFOR($Action.Case.New)}"
Why did they ahve to change it to:
"{!URLFOR($Action.Case.NewCase)}"
I would imagine because Case is a reserved word for programming with. They may not want to confuse it with Select Case.
Salesforce docs do not provide documentation for the Action properties, but you can find more information here on how to use them:
http://salesforcesource.blogspot.co.uk/2008/12/urlfor-function-finally-explained.html
The properties are exactly the same for all objects.