function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
GoForceGoGoForceGo 

Showing Validation Errors on Submit

 

I want to just add a submit button to the standard detail page. This is distinct from edit button. Before the user can submit, I want to enforce some validations.

So when I click the submit button, I want to change the status field to 'submitted' in the background,  which would fire a bunch of validation rules making sure certain fields are filled out.

 

 

The following VF Page is attached to the submit button shows the first validation error at top of the page..

 

.However, I would like to get to the page that would simulate the following; User clicked the "Edit" button and set the status field as submitted and tried to save the record, they would see a bunch of validation errors right next to the field. If that is not possible, I would like to atleast all the validation errors at the top of the page. Currently I see only the first one.

 

<apex:page standardController="CAPA__c" extensions="submitCAPAController" action="{!redirectToSubmissionResult}">
<apex:PageMessages />
<apex:detail />
</apex:page>

 

public with sharing class submitCAPAController {

       private ApexPages.StandardController stdCtrller;

       public CAPA__c CAPA {get;set;} 
              
       public submitCAPAController (ApexPages.StandardController stdController) {   

          stdCtrller = stdController;
          CAPA = (CAPA__c)stdController.getRecord();       	
       	
       }     
       
       public pageReference redirectToSubmissionResult() {
       	    
       	    CAPA.Status__c = 'Submitted';
       	    //stdCtrller.save() doesn't seem to get to the right page. 
       	    try { 
       	    	update CAPA;
       	    } catch(DmlException ex){
                ApexPages.addMessages(ex);
                return null;
            }
            return null; 
            
       }
}

 

 

 

Prafulla PatilPrafulla Patil

Try if you can use Transaction Control in this case        


http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_transaction_control.htm

Savepoint sp = Database.setSavepoint();

update CAPA;

Database.rollback(sp);

GoForceGoGoForceGo

Prafulla,

 

Thanks for the suggestion. I have used this approach before to test whether there are any validation errors but don't want to save the changes.

 

In this case, I am okay saving changes if status = 'submitted' and there are no validation errors.

 

It turns out that DMLException also just returns the first validation error - it doesn't give you all the validation errors - that is why I am seeing only the first one at the top of the page.

 

I don't know how I would duplicate the "save" button in standard UI and show the standard UI validation errors which validate all fields.