+ Start a Discussion
HelloSanHelloSan 

how to handle the exception in Order object trigger updating Opportunities

Trigger testOrder on Order (after insert,after update,after delete)
{
//logic
update newopplist //newopplist is list of opportunities
}
How to handle  the exception on  update newopplist and throw customize error message

 
Chandra Sekhar CH N VChandra Sekhar CH N V
include the required code inside a try catch block and use .addError() method to throw error message
Amit Chaudhary 8Amit Chaudhary 8
Please check below post for Trigger. I hope that will help you .
http://amitsalesforce.blogspot.com/2015/06/trigger-best-practices-sample-trigger.html

If you want to handle the Exception in Trigger . Then please follow below code.

Triggers can be used to prevent DML operations from occurring by calling the addError() method on a record or field. When used on Trigger.new records in insert and update triggers, and on Trigger.old records in delete triggers, the custom error message is displayed in the application interface and logged
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_exceptions.htm
https://developer.salesforce.com/page/An_Introduction_to_Exception_Handling
try{
     //Your code here
} catch (ListException e) {
     //Optional catch of a specific exception type
     //Specific exception handling code here
} catch (Exception e) {
     //Generic exception handling code here
} finally {
     //optional finally block
     //code to run whether there is an exception or not
}
An Introduction to Exception Handling
https://developer.salesforce.com/page/An_Introduction_to_Exception_Handling

Please let us know if this will help you

Thanks
Amit Chaudhary