0

I tried

c.clear(), 

accts.clear() and

contacts.clear()

on the controller after Insert c but it didn't work.

Visualforce page

<apex:page controller="SubmitCaseController">
    <h1>Submit New Case</h1>
    <apex:form >
        <apex:pageMessages />
        <table>
            <tr>
                <th>Your Name:</th>
                <td><apex:inputText value="{!Name}"/></td>
            </tr>
            <tr>
                <th>Your Email:</th>
                <td><apex:inputText value="{!Email}"/></td>
            </tr>
            <tr>
                <th>Your Account Number:</th>
                <td><apex:inputText required="true" value="{!acctNum}"/></td>
            </tr>
            <tr>
                <th>Title:</th>
                <td><apex:inputText required="true" value="{!Subject}"/></td>
            </tr>
            <tr>
                <th>Your Problem:</th>
                <td><apex:inputTextArea required="true" rows="5" value="{!Description}"/></td>
            </tr>
            <tr>
                <td><apex:commandButton value="Submit Case" action="{!submitCase}"/></td>
</tr>
        </table>
    </apex:form>

</apex:page>

Controller

public with sharing class SubmitCaseController {

    public Case c { get; set; }

    public String acctNum { get; set; }
    public String Name{ get; set; }
    public String email { get; set; }
    public String Subject { get; set; }
    public String Description { get; set; }



    public SubmitCaseController() {
        c = new Case();
    }

    public PageReference submitCase() {
     List<Account> accts = [SELECT Id, Name FROM Account WHERE AccountNumber = :acctNum];
        Contact contacts = [SELECT Id, Email FROM Contact WHERE Email= :email];

            if (accts.size() != 1) {
            ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.FATAL, 'Invalid account number');
            ApexPages.addMessage(msg);
            return null;
        } else {
            try {
                c.AccountId = accts.get(0).Id;
                c.SuppliedEmail = email;
                c.ContactId = contacts.Id;
                c.Subject = Subject;

  Database.DMLOptions dmlOpts = new Database.DMLOptions();
                dmlOpts.assignmentRuleHeader.useDefaultRule = true;
                c.setOptions(dmlOpts);

 INSERT c;

            ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.CONFIRM, 'Success! Your case has been registered.');
            ApexPages.addMessage(msg);

                return null;
 } catch (Exception e) {
                ApexPages.addMessages(e);
                return null;
            }
        }
    }
}
4
  • Try reRender.... Jan 13, 2015 at 17:24
  • <td><apex:commandButton value="Submit Case" action="{!submitCase}" renrender="block" /></td> .... this did not work.
    – LazyBones
    Jan 13, 2015 at 17:37
  • @sshah - please tell me you game the appropriate element the name of 'block' :smh
    – Eric
    Jan 13, 2015 at 18:15
  • yes, I changed the <apex:form id="block"> and then used the above thing.
    – LazyBones
    Jan 13, 2015 at 18:18

1 Answer 1

1

Added a few lines:

try {
                c.AccountId = accts.get(0).Id;
                c.SuppliedEmail = email;
                c.ContactId = contacts.Id;
                c.Subject = Subject;

  Database.DMLOptions dmlOpts = new Database.DMLOptions();
                dmlOpts.assignmentRuleHeader.useDefaultRule = true;
                c.setOptions(dmlOpts);

 INSERT c;

            ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.CONFIRM, 'Success! Your case has been registered.');
            ApexPages.addMessage(msg);
//----ADD------
c = new Case();
acctNum = null;
Name = null;
email = null;
Subject = null;
Description = null;
//----------
                return null;
 } catch (Exception e) {
                ApexPages.addMessages(e);
                return null;
            }

Just need to clear the info in those fields.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .