You need to sign in to do that
Don't have an account?
Chris110
How to displayed the trigger of error message
Hello everybody:
I created a trigger, and now there is an exception or error message, but I do not know how to display it on Visualforce page.
thanks for your help!
trigger SalaryRangeTrigger on JobPosition__c (before insert) { list<testtable__c> testData; for(JobPosition__c T: Trigger.new) { if(t.Salary__c!=null) { list<Salary__c> salaryId=[select id,maxPay__c,minPay__c,SalaryName__c from Salary__c where id=:t.Salary__c]; for(Salary__c dataId:salaryId) { if(t.Monthly__c < dataId.minPay__c || t.Monthly__c>dataId.maxPay__c) { //Trigger.new[0].Monthly__c.addError('not a valid account'); Trigger.new[0].addError('error messages!'); } testData=new List<testtable__c>(); testData.add(new testtable__c(minPay__c=dataId.minPay__c,maxPay__c=dataId.maxPay__c,jobId__c=dataId.SalaryName__c)); insert testData; } } } }
Trigger.new[0].addError('error messages!');
or
t.addError('error message!');t is an object;
how to Display the error on Visualforce
first add following tag on Page
<apex:pageMessages id="errorMessage"></apex:pageMessages>
tag on page , It will show the error that you have added in Trigger.new[0].adderror()
if solution works for you please mark as accepted it works for me :)
hope this will help you
Thanks,
Bala
All Answers
now
I know how to display the error message.
But how to stay on the same page(edit page or add page) when the trigger is running,
not PageReference to a new page.
somebody can help me:
how can we get the value of Visualforce control (messages value)on apex.
now
Logic can not determine whether the jump
I hope I said that to understand
first add following tag on Page
<apex:pageMessages id="errorMessage"></apex:pageMessages>
tag on page , It will show the error that you have added in Trigger.new[0].adderror()
if solution works for you please mark as accepted it works for me :)
hope this will help you
Thanks,
Bala
it's work
thank you very much
Hi,
I have the same issue of displaying error message handled in trigger on VF page.
For this i have added apex page messages tag... still the error is not being displayed on the same page.
The error i am facing is:
System.DmlException: Upsert failed. First exception on row 0 with id 00190000008lusuAAA; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Customer ID, Accounting Entity ID , Location ID and In Sync Flag cannot be Modified.: []
Please let me know if any soln.
Thanks!
Hi Bala, Your solution seemes to be not working for me. Is there any other way to display trigger errormessage in visualforce page.