1

I'm customizing Public Knowledge Base - to have a custom webform to enable users to save an case with required informations. But now when I submit the form - The page just reloads - and locks fields. Case is submitted - But I want to show feedback information for the user. idea is to hide contact apex component and showing a feedback component with a thankyou text. This I imagine to do by URL parameters as this is how I navigate to the Webform initially.

If I can manage the submit commandbutton to navigate to below url, it would be solved. http://xxx.force.com/Sitename/pkb_Home?cu=1&tu=1

Below is my Controller (examples, because originally code is quite large:

public PageReference submitCase() 
{
   try 
   {
        c.suppliedName = ''+ct.FirstName+' '+ct.LastName;
        c.Origin = 'Webform';
        Database.DMLOptions dmlOpts = new Database.DMLOptions();
        dmlOpts.assignmentRuleHeader.useDefaultRule = true;
        c.setOptions(dmlOpts);
        INSERT c;                
        PageReference reference = new PageReference('/pkb_Home?tu=1');
        //PageReference reference = new PageReference('www.google.dk'); 

        reference.setRedirect(true);
        //displayThankYou = true;
        return reference;
    } 
    catch (Exception e) 
    {
            ApexPages.addMessages(e);
            return null;
    }
}

Below is Apex Component:

<apex:component allowDML="true" controller="pkb_Controller">
<h2>{!$Label.PKB2_Contactform_H1}</h2>
<apex:form >
<apex:pageBlock ><p>{!$Label.PKB2_Contactform_Text}</p><br></br>
    <apex:pageBlockSection >
    <apex:inputField label="{!$Label.PKB2_Contactform_CategoryLabel}" value="{!c.SuppliedCategory__c}" required="true"/><br></br><br></br>
    <apex:inputField value="{!ct.FirstName}" required="true"/><br></br><br></br>
    <apex:inputField value="{!ct.LastName}" required="true"/><br></br><br></br>
    <apex:inputField label="{!$Label.PKB2_Contactform_EmailLabel}" value="{!c.SuppliedEmail}" required="true"/><br></br><br></br>
    <apex:inputField value="{!c.Subject}" required="true"/><br></br><br></br>
    <apex:inputField label="{!$Label.PKB2_Contactform_DescriptionLabel}" style="width:200px" value="{!c.Description}" required="true"/><br></br><br></br>
    <apex:inputFile title="{!$Label.PKB2_Contactform_AttachFileLabel}" filename="{!at.name}" contentType="{!at.contentType}" filesize="10000" size="50" value="{!at.body}"/><br></br><br></br> 
    <apex:commandButton value="Send" action="{!submitCase}"/>
    </apex:pageBlockSection>
    </apex:pageBlock>   
</apex:form>

2
  • I am guessing that you are trapping a DML exception in your catch block, that is why the page is reloading (return null just refreshes current page). Add this as the first line in the catch block system.debug('Error: ' + e.getMessage()); This will give you what the error is that is occurring. If you fix that error, then your code will not hit the catch block and should execute the redirect as expected. Commented Sep 19, 2015 at 12:27
  • Thanks, Will try that but Case is submitted in Salesforce just fine. So I'm guessing thats not the problem. Commented Sep 19, 2015 at 12:36

1 Answer 1

1

I agree with comments suggesting that adding debug statements would be wise. It always is when diagnosing problems.

Instead of redirecting to another page as you're currently attempting to do via visualforce, another way would be to use Javascript or jQuery as part of the Form Submit Button. After submitting the form, you can then "show" (reveal) a feedback form with the "Thank You" text and "hide" the contact component.

As you're aware, when using visualforce, this would need to be done as part of an Action method that your controller would implement as part of the Form Submission. So, not only do you submit the case, you also have an Action that hides the other component and replaces it with the feedback component.

Presumably this might get you around the issue of trying to sort out why your case is submitting but your page isn't redirecting.

I suspect it's likely that there's something else in your controller code that you've not shown us which is actually the culprit. Adding lots of debug statements should help you locate the actual source. If you've not created a unit test class for the controller, I'd highly recommend you do so as that might help you diagnose the root cause of your problem. This is referred to as Test-driven development.

You must log in to answer this question.

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