+ Start a Discussion
Anitha Reddy 14Anitha Reddy 14 

Write a trigger,When account record is inserted,check(Name=123)..If it contains 123,donot insert..Send error message that account name already exists.

Edwin VijayEdwin Vijay
trigger HelloWorldTrigger on Account (before insert) {
    for(Account a : Trigger.New) {
           if(a.name.contains('123')
                  a.addError ('You cannot insert an account with name containing 123');
    }   
}

Hope that helps!
Anitha Reddy 14Anitha Reddy 14
Thank you Edwin. Regards Anitha
Apoorv Saxena 4Apoorv Saxena 4
Hi Anita,

Please try the below code:
 
trigger checkAccountName on Account (before insert) {    
    for(Account acc:trigger.new){
        if(acc.name=='123'){
            acc.addError('Account name already exists.');
        }
    }
}

Please mark this question solved if this helps you !

Thanks,
Apoorv
Anitha Reddy 14Anitha Reddy 14
Thank You Apoorv.. Regards Anitha