+ Start a Discussion
Shawn ReichnerShawn Reichner 

Visualforce Page On Site Not Showing Validation Rule Message when Case is submitted

Hello,  I have an exposed Site with a basic Visualforce page using the standard case controller with an Extension to handle an Attachment upload.  All works great however I just added a new Validation rule to the Case Object where the BKR Job field needs to be in a certain format in order to allow the case to save.  The format the field is looking for is like the following 000V-11-00000.  Anything else not in that format should throw the Validation rule error message at the field.  What is happenign on the Site exposed VF page is the case shows it has been submitted to the user but the case is not created in the system because of the V RUle error, however the error message doe snot show on the VF page when submitting.  I am pasting my code below in hopes someone can help me figure this one out.  As you can see I have try catch and attemptign to show the error message any way I know how but it doesnt seem to diplay the error no matter what I try.  PLEASE HELP :) 

Controller Extension:

public with sharing class caseattachment
public case objcase{get;set;}
public String subj {get;set;}
public String description {get;set;}
public Attachment myAttachment{get;set;}
public string fileName{get;set;} 
public Blob fileBody{get;set;}

    public caseattachment(Apexpages.standardcontroller controller)
        objcase = new case();
        myAttachment =new Attachment();
    public pagereference save()
        String currentPage = null;
        Boolean isServiceReadinessPage = false;
        if(ApexPages.currentPage() != null && !Test.isRunningTest()) {
            currentPage = ApexPages.currentPage().getUrl();
            isServiceReadinessPage = currentPage.contains('Service_Readiness_Updated');
        if(objCase.Requested_Completion_Date__c != null) {
            objCase.Contract_Start_Date__c = objCase.Requested_Completion_Date__c;
            objCase.Requested_Completion_Date__c = null;
        if(objCase.Requested_Completion_Date_2__c != null) {
            objCase.Contract_End_Date__c = objCase.Requested_Completion_Date_2__c;
            objCase.Requested_Completion_Date_2__c = null;
        Boolean contractStartEndDateFieldsHaveValues = (objCase.Contract_Start_Date__c != null) && (objCase.Contract_End_Date__c != null);
        Boolean requiredFieldsHaveValues = true;
        //requiredFieldsHaveValues = requiredFieldsHaveValues && (objCase.Sales_Type__c != null);
        requiredFieldsHaveValues = requiredFieldsHaveValues && (objCase.Customer_Name__c != null);
        //requiredFieldsHaveValues = requiredFieldsHaveValues && (objCase.Request_Type_2__c != null);
        requiredFieldsHaveValues = requiredFieldsHaveValues && (objCase.Manufacturer__c != null);
        requiredFieldsHaveValues = requiredFieldsHaveValues && (objCase.Number_Of_Ports__c != null);
        requiredFieldsHaveValues = requiredFieldsHaveValues && (objCase.Number_Of_Users__c != null);
        requiredFieldsHaveValues = requiredFieldsHaveValues && (objCase.Contract_Start_Date__c != null);
        requiredFieldsHaveValues = requiredFieldsHaveValues && (objCase.Contract_End_Date__c != null);
        //requiredFieldsHaveValues = requiredFieldsHaveValues && (objCase.Salesperson__c != null);
        //requiredFieldsHaveValues = requiredFieldsHaveValues && (objCase.Sales_Engineer__c != null);
        requiredFieldsHaveValues = requiredFieldsHaveValues && (objCase.Trial_Account__c != null);
        if(requiredFieldsHaveValues || (objCase.VMR_or_Bridging__c != 'Bridging/VMR' && contractStartEndDateFieldsHaveValues) || (!isServiceReadinessPage && objCase.VMR_or_Bridging__c != 'Bridging/VMR')) {  
        //if(requiredFieldsHaveValues || objCase.VMR_or_Bridging__c != 'Bridging/VMR') {  
            insert objcase;
            } catch(DMLException e) {
                ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR, e.getdmlMessage(0));
            if (fileName != null && fileName.trim().length() > 0  && fileBody != null) {
            myAttachment  = new Attachment();
            Integer i=0;
            myAttachment .clear();
            myAttachment.Body = fileBody;
            myAttachment.Name = this.fileName; 
            myAttachment.ParentId = objcase.id;
            insert myAttachment;
            pagereference pr = new pagereference('/'+objcase.id);                           
            return pr;
        } else {
            ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Fill in all the required fields before saving.');
            return null;

VF Page code:

<apex:page standardcontroller="Case" extensions="caseattachment"
<img src="{!$resource.AVISPL_Logo2}"></img><b/><b/>
<apex:pageMessages id="errMsg" />
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection title="Professional Service / Onboarding Request" columns="1" showHeader="True" collapsible="False"> </apex:pageBlockSection>

<apex:pageBlock >
<apex:inputField value="{!Case.CaseNumber}"/>
<apex:pageBlockSection title="Requestor Information">
<apex:inputfield value="{!objcase.Requestor_s_First_Name__c}" required="True"/>
<apex:inputfield value="{!objcase.Requestor_s_Last_Name__c}" required="True"/>
<apex:inputfield value="{!objcase.Requestor_Email_Address__c}" required="True"/>
<apex:inputfield value="{!objcase.Requestor_s_Phone_Number__c}" required="True"/>
<apex:inputField value="{!objcase.Account_Name__c}" required="True"/>
<apex:inputField value="{!objcase.Sales_Type__c}" required="True"/>
<apex:inputField value="{!objcase.Customer_Name__c}" required="True"/>
<apex:inputField value="{!objcase.Customer_Type__c}" required="True"/>
<apex:inputField value="{!objcase.Customer_Points_of_Contact__c}" required="True"/>

<apex:pageBlockSection title="Description Information">
<apex:inputField value="{!objcase.Project_Name__c}" required="True"/>
<apex:inputField value="{!objcase.Request_Type_2__c}" required="True"/>
<apex:inputField value="{!objcase.Service_Type__c}" required="True"/>
<apex:inputField value="{!objcase.Connection_Type__c}"/>
<apex:inputField value="{!objcase.Description}" required="True"/>
<apex:inputField value="{!objcase.Manufacturer__c}" required="True"/>
<apex:inputField value="{!objcase.BKR_Opp_or_Quote__c}" label="BKR Job#" required="True"/>
<apex:inputField value="{!objcase.Messaging_Technology__c}" required="True"/>
<apex:inputField value="{!objcase.Target_Deadline__c}" required="True"/>
<apex:inputField value="{!objcase.TSG_Project_Manager_Budgeted_Hours__c}" required="True"/>
<apex:inputField value="{!objcase.TSG_Engineer_Programmer_Budgeted_Hours__c }" label="Engineer Budgeted Hours" required="True"/> <apex:inputField value="{!objcase.Project_Budgeted_Cost__c }" required="True"/>
<br/> >
<apex:pageBlockSection title="SOW PO & IPT (Attachment)">
<apex:inputFile id="fileToUpload" value="{!fileBody}" filename="{!fileName}" styleClass="input-file"/>
</apex:pageBlockSection> <apex:commandButton value="Submit Request" action="{!Save}" reRender="errMsg" />
<apex:outputLink value="http://avi-spl.force.com/profmanservicemainpage">Return To Main Page</apex:outputLink>
Shawn ReichnerShawn Reichner
Bala, I am using the page messages tag and n the vf page and also re rendering it on the command button. Unless I am not understanding or missing something about your comment I think that has already been attempted with no resolution. Thanks though, Shawn