Validation in trigger
Handler class
-------------
public class ErrorMessage
{
public static void throwError(List accList)
{
for(Account a:acclist)
{
//acclist is a collection of new records
if(a.site==null)
{
//a is the reference variable name
//Accessing the field name(Reference variable.Field name)
a.addError('Should not be empty');
//addError method is used to display an error message
}
}
}
}
Trigger code
------------
trigger AccountTrigger on Account (before insert)
{
ErrorMessage.throwError(Trigger.new);
//This event will be fired when the user creates a record
//As soon as user clicks on save then it will check for site value.If it's empty then it will throw an error message
}
-------------
public class ErrorMessage
{
public static void throwError(List
{
for(Account a:acclist)
{
//acclist is a collection of new records
if(a.site==null)
{
//a is the reference variable name
//Accessing the field name(Reference variable.Field name)
a.addError('Should not be empty');
//addError method is used to display an error message
}
}
}
}
Trigger code
------------
trigger AccountTrigger on Account (before insert)
{
ErrorMessage.throwError(Trigger.new);
//This event will be fired when the user creates a record
//As soon as user clicks on save then it will check for site value.If it's empty then it will throw an error message
}
Comments
Post a Comment