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
Nehru komuNehru komu 

Hi, I'm Writing an Apex Trigger to Count number of Times Account Name updated

PawanKumarPawanKumar
Hi Nehru,
Please try below code. But please create one integer custom field on account to store the value.

trigger AccountTrigger on Account (before update) {
    for (Account eachAccount: Trigger.new) {
        String newAccountName = (Trigger.newMap.get(eachAccount.Id)).Name;
        String oldAccountName = (Trigger.oldMap.get(eachAccount.Id)).Name;
        
        if(!newAccountName.equals(oldAccountName)){
            // you update your count Account.Custom_Count_Field
            eachAccount.custom_count_field=eachAccount.custom_count_field+1;
        }
    }
}

Regards,
Pawan Kumar
PawanKumarPawanKumar
please let us know if it helps you.