You need to sign in to do that
Don't have an account?
Marketing Marketing 27
Validation Rule Messages Not Showing Up On Visualforce Page
I have a custom VF page that helps users make a certain type of opportunity. It is triggered by a button on the opportunity record page.
I have the <apex:pagemessages /> tag on the custom page and the below try catch block in my controller extension. However, when I intentionally leave fields out to try and trip the validation rule, it doesn't show it. it just redirects me to the original opportunity when I click save.
can someone please tell me what I'm doing wrong?
I have the <apex:pagemessages /> tag on the custom page and the below try catch block in my controller extension. However, when I intentionally leave fields out to try and trip the validation rule, it doesn't show it. it just redirects me to the original opportunity when I click save.
can someone please tell me what I'm doing wrong?
public PageReference Save(){ try{ insert TD2nd; } catch(System.DmlException e){ String error = e.getMessage(); Integer numDML = e.getNumDml(); system.debug('num dml exceptions: '+numDML); ApexPages.addMessages(new ApexPages.message(ApexPages.Severity.ERROR, error)); } TD1st.X504_Related_Opportunity__c = TD2nd.Id; TD1st.X504_Combined_Amount__c = getCombinedAmount(); update TD1st; PageReference originalOpp = new ApexPages.StandardController(TD2nd).view(); Return originalOpp; }
https://www.biswajeetsamal.com/blog/display-of-validation-rule-error-on-visualforce-page/
All Answers
Try replacing from To
And then in each command button or action where there is a possibility of displaying an error you have to add to your reRender attribute the apex:pageMessages id:
For more reference refer this :-
https://salesforce.stackexchange.com/questions/104650/validation-rules-error-not-seen-in-custom-vf-page
https://developer.salesforce.com/forums/?id=906F0000000990kIAA
Hope to have helped!
Regards.
Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.
It still just redirects to the original opportunity without any error message when I hit save.
So how do I get it so that the pagereference gets returned only if the try catch block passes?
https://www.biswajeetsamal.com/blog/display-of-validation-rule-error-on-visualforce-page/