You need to sign in to do that
Don't have an account?
Throw an error at top of standard page from Trigger
Hi All. I am positive I am missing something simple. I would like to throw an error on a standard page - at the top of the page - when a boolean has been set on the record. This effectively locks the reord from being adited any further. Code follows:
You can see the error I would like to throw. Problem is that the error thrown looks like this:
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger SalesorderTrigger caused an unexpected exception, contact your administrator: SalesorderTrigger: execution of BeforeUpdate caused by: System.FinalException: SObject row does not allow errors: Class.SOTriggerHelper.validateSOCanBeSubmitted: line 10, column 1
What am I missing?
public class myException extends Exception {} public static void validateSOCanBeSubmitted(List<Netsuite_Sales_Order__c> newTrigger, List<Netsuite_Sales_Order__c> oldTrigger, Map<Id, Netsuite_Sales_Order__c> oldMap){ for(Netsuite_Sales_Order__c so :oldTrigger){ if(so.Netsuite_SO_Entered__c == true){ so.addError( new myException('This SO has been locked because it has already been submitted')); } }
When used on Trigger.new in before insert and before update triggers, and on Trigger.old in before delete triggers, the error message is displayed in the application interface.
All Answers
When used on Trigger.new in before insert and before update triggers, and on Trigger.old in before delete triggers, the error message is displayed in the application interface.