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
kaustubh chandratrekaustubh chandratre 

Write a trigger on Account. If user is updating the name of an account then throw an error message "Account Name Cannot be Changed."

CharuDuttCharuDutt
Hii kaustubh
trigger AccountTrigger on Account (before update) {

        for(Account Acc : Trigger.new) { 
           if(Acc.Name != trigger.OldMap.get(Acc.Id).Name){
           Acc.Name.AddError('Account Name Cannot be Changed.');
        	}
        }
}

################################################################
You Can Also Try VAlidation Rule

 ISCHANGED(Name)
Please Mark It As Mark it As Best Answer If It Helps
Thank You!

 
Suraj Tripathi 47Suraj Tripathi 47
Hi kaustubh,

trigger AccountNameTrigger on Account (before update) {

if(Trigger.isUpdate && Trigger.isBefore)
{
        for(Account AccountObj : Trigger.new) { 
           if(AccountObj.Name != trigger.OldMap.get(AccountObj.Id).Name){
           AccountObj.addError('Sorry! You can\'t change the account name');
            }
        }
}
}


I hope you find the above solution helpful. If it does, please mark it as the Best Answer to help others too.
Thanks and Regards,
Suraj Tripathi
Vijayendra PatilVijayendra Patil
it will work but when you will update another field of Account still it will give same error.