You need to sign in to do that
Don't have an account?

My trigger code in below how writte same code Apex Trigger help class
Create a Trigger on the Account Object, to make sure each Account Record should have "Rating, Phone and Fax Field values".
Object Name : Account Object.
Event Name : Before Insert.
trigger AccountsTrigger on Account (before insert)
{
if(Trigger.isInsert && Trigger.isBefore)
{
for(Account accRecord : Trigger.New)
{
if(accRecord.Rating == Null || accRecord.Rating == '')
accRecord.Rating.AddError('Please Select the Rating Value.');
else if(accRecord.Phone == Null || accRecord.Phone == '')
accRecord.Phone.AddError('Please Enter the Contact Number.');
else if(accRecord.Fax == Null || accRecord.Fax == '')
accRecord.Fax.AddError('Please Enter the Fax Number.');
}
}
}
try with below code.
trigger: Class: If this helps, Please mark it as best answer.
Thanks!!
All Answers
Please,try like this.
trigger AccountTrigger01 on Account (before insert) {
if(Trigger.isBefore && Trigger.isInsert){
for(Account acc : Trigger.new){
if(acc.Phone == Null && (acc.Rating == Null && acc.Fax == Null)){
acc.Phone.addError('Please, enter phone number');
acc.Rating.addError('Please,select the rating value');
acc.Fax.addError('Please,enter fax number');
}
}
}
}
If, it works please mark it is best answer.
You can do this by using validation rule.
If this helps, Please mark it as best answer.
Thanks!!
try with below code.
trigger: Class: If this helps, Please mark it as best answer.
Thanks!!
Ankaiah thanks got it
https://developer.salesforce.com/forums/ForumsMain?id=9062I000000Ue6jQAC