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
❤Code❤Code 

trigger for auto number by record types

Hi,

I need to have a trigger on Account Object. My requirement is - 

1. There is two recordtypes on account object acc1, acc2.
2.  When i will create a record by select acc1, a custom field (account number ) should be updated with acc10001.
3. Similarly When i will create a record by select acc2,  custom field (account number ) should be updated with acc20001 not by acc2002.

Kindly help.

Regards
 
SunidharSunidhar
trigger recordTypeUpdate on Account (before insert, before update) {
    for(account acc : trigger.new) {
        if(acc.RecordType.name == 'acc1')
            acc.accountNumber = acc.RecordType.name + '001';
        else if(acc.RecordType.name == 'acc2')
            acc.accountNumber = acc.RecordType.name + '002';
    }
}
Mark it as best answer if it solves ur requirement.