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
ManidManid 

hai guys i am trying t o write code for this but i am not getting would please help me

 write a trigger on Account, While inserting a account  name value as ‘someName’ ended with ‘text’ ex: ‘renuText’.
 it should through an error On Account Object if name field has 'text' 
vikas chand 18vikas chand 18
Hi manid,
 
trigger TextError on Account (Before Insert) {
    For(Account acc : trigger.new){
        if(acc.name.contains('text')){
         acc.addError('you cannot add the "Text" in name field'); 
        } 
    }
}

 
Saurabh Tripathi 18Saurabh Tripathi 18
Write a trigger for this like:-
trigger checkTrigger on Account(before insert)
{
list<Account> acc=Trigger.new;
for(integer i=0;i<acc.size();i++)
{
if(acc.get(i).Name.contains('text'))
{
acc.get(i).addError('Name contains Text....Please make the mendatory changes');
    break;
}
}
}


This logic will stop acc to be saved if the name contains (''text") anywhere....
Hope this helps.....
Dinesh MultaniDinesh Multani
Use below code
 
trigger Test on Account (after insert,after update) {
    
    for(Account Act : trigger.New)
    {
    
       if(Act.Name.endsWith('Test'))
       {
          Act.addError('Name contains Test');
          return;
       }
      
       
    }

}

 
ManidManid
thank you guys . If we do it like admin.
 write Validation rule for above scenario while inserting the record and Validation rule should not fire while updating form workflow it should accept.
Dinesh MultaniDinesh Multani

I don’t think you can achieve same by simple Validation Rule..

Hope this helps and Mark best answer which you liked.

vikas chand 18vikas chand 18
Hi Manid,

you can write Validation also for above scenario.

you can put
CONTAINS(Name,"text")

this code on validation formula editer only where Name is the Field Name of account Object.

If this code fullfill you requirement then pls mark as best answer which helps others also.

Thanks
Vikas
Dinesh MultaniDinesh Multani
I hope Contains wont work . You can use below 

if(RIGHT(Name, 4)== 'Text',true,false)

User-added image
ManidManid
at the time of creation only this will fire . at the time editing it doesn't fire 
Dinesh MultaniDinesh Multani
Use ISNEW() function.