trigger accountTestTrggr on Account (before insert, before update) { for(Account acc : Trigger.new) { if(acc.MailingCity == null) { acc.addError('Mailing City Should not be Empty'); } } }
Advice:
why you are not using Validation rule or Use PageLayout Required / Field Level required Options.
Hi Venky , Srikant is correct basically you should go for other option as you have . Still as you want that ,you can write trigger in two different ways to get error in two different level .
Please try with below code it will help !!
//Error will display in field level
trigger ValidationTrigger on Account (before insert,before update) {
for(Account acc :Trigger.new){
if (acc.Type == null)
acc.Type.addError('Type Mandatory ');
}
}
//Error will display in record level
trigger ValidationTrigger on Account (before insert,before update) {
for(Account acc :Trigger.new){
if (acc.Type == null)
acc.addError('Type Mandatory');
}
}
Use following code:
trigger accountTestTrggr on Account (before insert, before update) {
for(Account acc : Trigger.new)
{
if(acc.MailingCity == null)
{
acc.addError('Mailing City Should not be Empty');
}
}
}
Advice:
why you are not using Validation rule or Use PageLayout Required / Field Level required Options.
Hope its help!!
Thanks!
HI Venky ,
Hi Venky ,
Srikant is correct basically you should go for other option as you have .
Still as you want that ,you can write trigger in two different ways to get error in two different level .
Please try with below code it will help !!
Let me know if it helps !!
Thanks
Manoj
Thanks!