You need to sign in to do that
Don't have an account?

How display Error message based on check box otherwise allow save update record?
Hi,
trigger AccountDuplicateTrg on Account (before insert,before update)
{
Map<string,Account> accMap = new Map<string,Account>();
set<string> accSet = new set<string>();
for(Account acc : Trigger.new)
accSet.add(acc.name);
for(Account a : [select id,name from Account where name in : accSet])
accMap.put(a.name,a);
for(Account acc1 : trigger.new)
{
if(accMap.containskey(acc1.name))
if(Trigger.isInsert){
acc1.addError('There is another account in the system with this exact name and is a likely duplicate');
}
else if(Trigger.isUpdate){
acc1.addError('There is another Account with the same name as this one. Please navigate to the Account tab');
}
}
}
How to apply below senario above trigger updation time
I created a check box named "displayerror". Now in trigger if this check box is true, then throw the error. If check box is false then save the record and have the default value for this check box as true.So when user gets this error he can know the existence of a duplicate account and then in order to save the account he can uncheck the check box which inturn will save the record.
please help me...
trigger AccountDuplicateTrg on Account (before insert,before update)
{
Map<string,Account> accMap = new Map<string,Account>();
set<string> accSet = new set<string>();
for(Account acc : Trigger.new)
accSet.add(acc.name);
for(Account a : [select id,name from Account where name in : accSet])
accMap.put(a.name,a);
for(Account acc1 : trigger.new)
{
if(accMap.containskey(acc1.name))
if(Trigger.isInsert){
acc1.addError('There is another account in the system with this exact name and is a likely duplicate');
}
else if(Trigger.isUpdate){
acc1.addError('There is another Account with the same name as this one. Please navigate to the Account tab');
}
}
}
How to apply below senario above trigger updation time
I created a check box named "displayerror". Now in trigger if this check box is true, then throw the error. If check box is false then save the record and have the default value for this check box as true.So when user gets this error he can know the existence of a duplicate account and then in order to save the account he can uncheck the check box which inturn will save the record.
please help me...
The above will throw error message in account object when 'disaplyerror' checkbox field is enabled
if(<DisplyError(Checkboxfield)>) Add this Line
Try this
Shaijan
Try this (Assuming API Name for checkbox is displayerror__c)
else if(Trigger.isUpdate){
if(acc1.displayerror__c){
acc1.addError('There is another Account with the same name as this one. Please navigate to the Account tab');
}
else{
acc1.displayerror__c = true;
}
}
Regards,
Bhanu Mahesh
When i will edit existing record and click save that time system will check there is any same account name in database and with displayerror__c is true it will display error .other wise allow save functionality without error how?.
Try this
trigger AccountDuplicateTrg on Account (before insert,before update)
{
Map<string,Account> accMap = new Map<string,Account>();
set<string> accSet = new set<string>();
for(Account acc : Trigger.new)
accSet.add(acc.name);
for(Account a : [select id,name from Account where name in : accSet])
accMap.put(a.name,a);
for(Account acc1 : trigger.new)
{
if(accMap.containskey(acc1.name)){
if(Trigger.isInsert){
acc1.addError('There is another account in the system with this exact name and is a likely duplicate');
}
else if(Trigger.isUpdate){
if(acc1.displayerror__c){
acc1.addError('There is another Account with the same name as this one. Please navigate to the Account tab');
}
else{
acc1.displayerror__c = true;
}
}
}
}
}
Regards,
Bhanu Mahesh
I tried this code but not working already duplicate exist in my database and check box also "True" this sistuation its not throwing an error.but still its allowing save.
Note:Bydefault checkbox is true
for contactupsert :
On Click "Save" button only update those records which has checkbox is checked otherwise skip.
created apex class and vf page trick code