Play Games

Search This Blog

Monday, December 16, 2013

How to display error message from trigger? (or) display validation error from trigger

We can display error messages from trigger.

field.addError(string):
     It places the specified error message on that field in the salesforce user interface and prevents any DML operation from occuring .
When used in visualforce controllers,if there is any inputfield component bound to field,the message is attached to the component.

This method is special because the field identifier is not actually the invoking object---the sobject record is the invoker.
 The following trigger example shows how to display error messages.

trigger testing2 on Account (after insert,after update) {

for (Account newOpp : Trigger.new) {
   
       newOpp .addError('See error  message will appear when u insert or update an account');
   

}
}

. 


  


No comments:

Post a Comment