function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
prasanth puvvada 4prasanth puvvada 4 

override validation rule using trigger.

hello i worte this validaton rule on standard object called  "account"   rule is  AnnualRevenue <= 50000

so i worote this beforetrigger and this is not working. please help me to write the correct trigger code.
 
trigger firsttrigger on Account (before insert) {
for(account a:trigger.new)
{
    a.AnnualRevenue > 30000;
}
}

 
Best Answer chosen by prasanth puvvada 4
Amit Chaudhary 8Amit Chaudhary 8
Please try below code:-
trigger firsttrigger on Account (before insert) 
{
	for(account a:trigger.new)
	{
		if(a.AnnualRevenue > 30000)
		{
			a.addError('Add your error msg here');
		}
	}
}
Please mark this as solution if this will help you. So that if some one has same issue this post can help.

Thanks,
Amit Chaudhary

All Answers

Amit Chaudhary 8Amit Chaudhary 8
Please try below code:-
trigger firsttrigger on Account (before insert) 
{
	for(account a:trigger.new)
	{
		if(a.AnnualRevenue > 30000)
		{
			a.addError('Add your error msg here');
		}
	}
}
Please mark this as solution if this will help you. So that if some one has same issue this post can help.

Thanks,
Amit Chaudhary
This was selected as the best answer
prasanth puvvada 4prasanth puvvada 4
i always love u your fast response and best answer.  Thanks again .........................
Amit Chaudhary 8Amit Chaudhary 8
your always welcome. Happy to help