+ Start a Discussion
angusgrantangusgrant 

Custom validation rules and vf apex extension

This is driving me mad. I have a vf "contacts" page in which I have created a very simple validation rule.

 

 

$RecordType.Name = "Oxford University Applicant" && NOT(RIGHT( Email , 9) = ".ox.ac.uk")

 

 I am using the standard controller for the contacts object with an apex controller extension to allow me to add data into other objects in the sf database.

 

My issue is that  the visulaforce does not acknowledge the validation rule on insert and instead of receiving a friendly error message to the vf page "sorry you must enter a correctly formatted email address" I receive an error via email. With the following message: FIELD_CUSTOM_VALIDATION_EXCEPTION.

 

Can I capture this error message? If so how? Looking at the documentation I tried this:

 

Contact.RecordTypeId = contactrecordtypeid; try { insert Contact; } catch (DmlException de){ System.debug('Data exception:'+ de.getMessage());} catch (Exception e) { System.debug('General exception:'+ e.getMessage()); }

 

 Which appears to stop me recieving the error via email but does not stop the execution of the rest of the code or return a error message to the vf tag <apex:pageMessages /> as expected?

 

Or do I have to write some apex code that does exacly the same thing as the validation code in which case how do I check that the last 9 charcters in apex are the same as the email prefix required?

 

Thanks 

 

 

Angus

 

 

 

angusgrantangusgrant
Bizarrely this issue is no longer an issue and I am now receiving the error handling as I hoped. I guess somewhere someone fixed this issue?!?!
charu setiacharu setia

Hi,

 

I am facing a similar issue. Can you send me the code for this particular problem?

jhugheyjhughey

Contact.RecordTypeId = contactrecordtypeid; try { insert Contact; } catch (DmlException de){ ApexPages.addMessages(de); catch (Exception e) { ApexPages.addMessages(e); }