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
Mark YoungMark Young 

Firing validation rules from code (and callbacks)

Hi,

As part of VisualForce development we wanted to be able to incorporate standard object validation messages.

Because these pages are part of a wizard, we are using a temporary object which doesn't ever get saved (at the end of the wizard it gets transformed into other objects).  Each page we need to determine if input is valid, and instead of using custom coded validation, it would be nice to be able to use object validation.

What I've really like would be a method that says 'testValidationRules()' or 'testSave()'.

Currently we're using code like...
Code:
boolean success = false;

Savepoint sp = Database.setSavepoint();
try
{
    insert obj;
    success = true;
}
catch (DmlException ex)
{
    ... render and process errors ...
}
Database.rollback(sp);

 This all works great, except for pages which then go and do a Callout (get the 'You have uncommitted work pending. Please commit or rollback before calling out' message).

So...
  • Is there a way to fire validation rules without saving the object?
  • Is there any way to get around the Callout issue above (i.e. even though I am rolling back database changes it still complains)?
Thanks