You need to sign in to do that
Don't have an account?
Redtag
Return Casenumber from Sites Case Submit Form
I've modified the Web to Case form on Developerforce Quickstarts Creating Custom Web-To-Case Forms
What I've done is redirect the user to a thankyou page upon pressing the submit button. But what I really need is for the Casenumber to be shown on the thankyou page. At the moment the casenumber does not show. I have checked the permissions and they are fine. The problem I have is how to pass the value from the first page to the thankyou page. Any help greatly appreciated.
Here is my page:
<apex:page controller="SubmitCaseController" title="Case thank you page" showHeader="false" standardStylesheets="true"> <apex:composition template="{!$Site.Template}"> <apex:insert name="header"> <c:SiteHeader /> <hr/> </apex:insert> <apex:define name="body"> <br/> <center> <apex:outputText value="Your information is saved. Thank you for your interest!"/> <br/> <apex:outputText value="Your Case Reference Number is: {!c.casenumber}"/> </center> <br/> <br/> </apex:define> </apex:composition> </apex:page>
And here is the controller:
public class SubmitCaseController { public Case c { get; set; } public SubmitCaseController() { c = new Case(); } public string casenum; // This method cancels the wizard, and returns the user to the // Submit case page public PageReference cancel() { PageReference SubmitCasePage = new PageReference('/apex/SubmitCase'); SubmitCasePage.setRedirect(true); return SubmitCasePage; } public PageReference SubmitCase() { List<Contact> cons = [SELECT Id, email, AccountId, CreatedDate FROM Contact WHERE email = :c.SuppliedEmail order by CreatedDate desc]; if (cons.size() < 1) { ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.WARNING, 'Please enter an email that matches our records'); ApexPages.addMessage(msg); return null; } else { try { c.ContactId = cons.get(0).Id; c.AccountId = cons.get(0).AccountId; // Specify DML options to ensure the assignment rules are executed Database.DMLOptions dmlOpts = new Database.DMLOptions(); dmlOpts.assignmentRuleHeader.useDefaultRule = true; c.setOptions(dmlOpts); // Insert the case INSERT c; casenum = c.CaseNumber; return new PageReference('/casethankyou'); } catch (Exception e) { ApexPages.addMessages(e); return null; } } } }
And here is the SubmitCase page:
<apex:page controller="SubmitCaseController" title="Submit Case" showHeader="false" standardStylesheets="true"> <script> function confirmCancel() { var isCancel = confirm("Are you sure you wish to cancel?"); if (isCancel) return true; return false; } </script> <apex:composition template="{!$Site.Template}"> <apex:insert name="header"> <c:SiteHeader /> <hr/> </apex:insert> <apex:define name="body"> <apex:form > <apex:messages id="error" styleClass="errorMsg" layout="table" style="margin-top:1em;"/> <apex:pageBlock title="" mode="edit"> <apex:pageBlockButtons > <apex:commandButton value="Submit" action="{!SubmitCase}"/> <apex:commandButton action="{!cancel}" value="Cancel" onclick="return confirmCancel()" immediate="true"/> </apex:pageBlockButtons> <apex:pageBlockSection title="New Enquiry" collapsible="false" columns="1"> <table> <tr> <th>Customer Name:</th> <td> <apex:inputText required="true" value="{!c.SuppliedName}"/></td> </tr> <tr> <th>Customer Email:</th> <td><apex:inputText required="true" value="{!c.SuppliedEmail}"/></td> </tr> <tr> <th>Business Name:</th> <td><apex:inputText required="true" value="{!c.SuppliedCompany}"/></td> </tr> <tr> <th>Subject:</th> <td><apex:inputText required="true" value="{!c.Subject}"/></td> </tr> <tr> <th>Your Problem:</th> <td><apex:inputTextArea required="true" rows="5" value="{!c.Description}"/></td> </tr> </table> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:define> </apex:composition> </apex:page>
You'll need to query the information back from the database, as the case number is automatically generated when the record is saved:
All Answers
You'll need to query the information back from the database, as the case number is automatically generated when the record is saved:
Thanks - very obvious when Bob pointed it out.
Whenever a Thankyou page is refereshed new case is generated how to stop this.
I followed this thread to implement the custom 'thank you' page for a Web-To-Case integration, with the intension of populating the CaseNumber value to be exposed and reflected back in the 'thank you' page. Unfurtunately, something isn't working, and I would be glad to receive some assistance. Here's what I did and:
1. VisualForce Page - 'SubmitCase'. Pretty straightforward, the initial Submit a Case page:
2. Apex Class - 'SubmitCaseController' :
3. VisualForce Page - Thank You named 'casethankyou':
Unfutunately, the output is missing the Case Number:
I raised the debug log and can note the Case Number print for debug purposes, so am quite sure the last bit is around setting the value to the appropriate variable, and I'm not sure how.
Can I please ask for your assistance?
Thank you.