You need to sign in to do that
Don't have an account?
sales@myvarma
triggers on account records
instead error
i must update the new values to old record with same name help me
trigger accounttrigger on Account (before insert, before update) {
Map<String, Id> mapAccount = new Map<String, Id>();
Set<String> setAccName = new Set<String>();
for(Account acc : trigger.new)
setAccName.add(acc.Name);
for(Account acc : [ SELECT Id, Name FROM Account WHERE Name IN :setAccName ] )
mapAccount.put(acc.Name, acc.Id);
for(Account acc : trigger.new)
if(mapAccount.containsKey(acc.Name) && mapAccount.get(acc.Name) != acc.Id)
acc.addError( 'There is already another Account with the same Name. ' +
mapAccount.get(acc.Name) + '\'>' + acc.Name + '</a>', FALSE );
}
i must update the new values to old record with same name help me
trigger accounttrigger on Account (before insert, before update) {
Map<String, Id> mapAccount = new Map<String, Id>();
Set<String> setAccName = new Set<String>();
for(Account acc : trigger.new)
setAccName.add(acc.Name);
for(Account acc : [ SELECT Id, Name FROM Account WHERE Name IN :setAccName ] )
mapAccount.put(acc.Name, acc.Id);
for(Account acc : trigger.new)
if(mapAccount.containsKey(acc.Name) && mapAccount.get(acc.Name) != acc.Id)
acc.addError( 'There is already another Account with the same Name. ' +
mapAccount.get(acc.Name) + '\'>' + acc.Name + '</a>', FALSE );
}
You cannot get the acc.id for Before Trigger. So instead of checking != acc.id use
This will write up the error message if you try to create or update the Account with existing name.
Please mark this answer as best answer if it resolves your problem