3

I have a Visualforce page with a custom controller. Whenever there is a validation error on saving, the user is shown a white page with the text SObject row does not allow errors:

enter image description here

I have followed the documentation and ensured that my save method contains a try/catch which adds error messages like so:

try{
...
}
catch(DmlException ex){
    ApexPages.addMessages(ex);

    return null;
}

My Visualforce page also has the <apex:pageMessages showDetail="true" /> element on it.

I can see the validation errors appear in the logs: enter image description here

Why is this page not showing validation messages, and instead it is just showing this unhelpful white page?

  • Your controller is handling your validations? – EricSSH Apr 6 '16 at 21:51
  • No, it's just standard field validation. – Chris Payne Apr 6 '16 at 21:52
  • Can post some more of your vf? – EricSSH Apr 6 '16 at 22:13
  • 1
    Based on e.g. SObject row does not allow errors in Salesforce before trigger the problem originates in a trigger and presumably a FinalException is not a DmlException so your controller doesn't catch it so producing the unhandled exception white page. (From a quick test looks like a FinalException can't be caught in Apex.) So the fix is to fix the trigger.. – Keith C Apr 6 '16 at 22:20
  • @EricSSH my VF page is quite large. What specifically would you be interested in seeing, and I'll paste the relevant subset of the page? – Chris Payne Apr 6 '16 at 22:24
3

Based on e.g. SObject row does not allow errors in Salesforce before trigger the problem originates in a trigger and presumably a FinalException is not a DmlException so your controller doesn't catch it so producing the unhandled exception white page. (From a quick test it looks like a FinalException can't be caught in Apex.) So check any triggers that might be kicked off by the ... code in your controller and see if they attempt to call addErrors on objects that are not part of the Trigger context.

The fix is to fix the trigger(s). You may be able to get more detail of where the error originates (such as a stack trace) in the white page by setting "Development Mode" for the user that you are testing under.

  • I'm only just starting out with SF, and never even knew about Development Mode. +1 for that alone- teach a man to fish and all that. – Chris Payne Apr 6 '16 at 22:43
  • Do you know if there is a quick way to disable all triggers? There appears to be quite a few in this organisation and I'd like to be able to quickly check if a trigger is the cause before I manually check each one – Chris Payne Apr 6 '16 at 22:50
  • @ChrisPayne Yep - I found that tip on this site a while ago. – Keith C Apr 6 '16 at 22:50
  • If the triggers are local (not in a managed package) you should be able to get info from the debug log on where the problem originates (if the "Development Mode" stack trace doesn't include that info). No way of turning triggers off in a production org I'm afraid - people just have to add their own logic (such as custom setting flags) to allow that and often such logic won;t be there. – Keith C Apr 6 '16 at 22:54
  • I've now ruled out triggers, but I know roughly the area of code that is causing the error (commenting it out allows the validation to work). It's got something to do with how I get the instance of the Event object to be saved. I'm using (Event)Schema.getGlobalDescribe().get('Event').newSObject(null, true) so that default values are populated, but this mustn't play nice when saving (and why should it? I should be getting the instance from the values posted). This is an oversight in the controller on my behalf, it shouldn't be too hard to fix. Thanks for teaching me to fish! – Chris Payne Apr 6 '16 at 22:59
0

Had just to fix this in one of my classes (but I had this solution in other classes):

    // standard controller wasn't displaying field validation errors on VF
    // sc.save();
    update yourRecord;
  • I don't get it.. – EricSSH Apr 6 '16 at 22:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.