Trying to revise an existing external Visualforce page and Apex class with error messages (so it appears on the Visualforce page). The debug logs show that it's rendering the message but it's not actually doing it on the Visualforce page. It actually directs the users to the Unauthorized page specified in my site.
14:32:47.254 (2858142514)|VF_PAGE_MESSAGE| [this was my message]
I have this in my VF page:
<apex:form style="padding-left: 20px; padding-right: 20px;">
<apex:pageMessages />
</apex:form>
and this in my Apex:
catch (System.DmlException e) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, e.getDmlMessage(0)));
return null; // Return null to stay on the same page
}
It's not displaying the message in the VF page and just redirects them to the Unauthorized page automatically. This is the DML error (which is expected):
System.DmlException: Update failed. First exception on row 0 with id [record Id]; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, [validation error]
Added this to my Apex:
catch (System.DmlException e) { ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, e.getDmlMessage(0))); return null; // Return null to stay on the same page }
And this to my Visualforce Page:
<apex:form style="padding-left: 20px; padding-right: 20px;"> <apex:pageMessages /> </apex:form>