• Raj singh 61
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

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>