In Account Sobject i have added two check-box's 1.Administrative Office and 2.Data Center
when user enter name and check anyone of it then Account Name is like Sam (A)/(D).
which i did with trigger using before insert event, Thats fine. Now when client edit the Account and change the checkbox it should update the Name again like Sam (D)/(A) according. But not updating with this code
here is my Trigger code for reference
trigger accName on Account (before insert, before update) {
List<Account> acc;
if (Trigger.isBefore) {
if (Trigger.isInsert) {
for(Account a:Trigger.New) {
if(a.Administrative_Office__c == True) {
a.Name = a.Name + ' ( A ) ' ;
}
else if(a.Data_Center__c == True) {
a.Name = a.Name + ' ( D ) ' ;
}
else {
if (Trigger.isUpdate) {
List<Account> accn = new List<Account>();
accn = [SELECT Id, Name
FROM Account
WHERE Id IN: Trigger.oldMap.keySet()
LIMIT 1];
for (Account au : accn) {
if(au.Administrative_Office__c == True) {
au.Name = au.Name + ' ( A ) ' ;
}
else if(au.Data_Center__c == True) {
au.Name = au.Name + ' ( D ) ' ;
// au.Name = au.Name;
}
update accn;
}
}
}
insert a;
}
}
}
}