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
BARJRDBARJRD 

Validation routine in a controller

I would like to create a generic validation routine in a controller - i.e., when the Save button is clicked on a page, the validation routine executes, errors are trapped, and the cursor/focus is placed in the appropriate field on the page.

 

I have a general idea of how this should work, but not sure how to have the page communicate with the controller.

 

Thanks,

Barb R.

CaptainObviousCaptainObvious

Here's a simplified view of how you could implement this:

 

First, override the object's New or Edit buttons with a Visualforce Page.

 

In the  Visualforce page, add your controller as an extension

 

<apex: page standardController="Your_Object__c" extensions="Your_Controller_Ext">

 

Use a command button on the visualforce page to "communicate" with the controller

 

<apex:commandButton value="Save" action="{!save}" / >

 

Define your custom validation/save routine in the controller:

 

public class Your_Controller_Ext{

    public PageReference save(){

        //Your validation/save routine goes here

    }

}

 

BARJRDBARJRD

Thanks, Captain...I was looking more for how to set the screen focus on a field that had failed vailidation in the controller.

 

Barb