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

how to restrict trigger firing using hierchy custom setting
hi I write a trigger which blocks insertion of duplicate records in account object.but i want for particular user to the trigger should not be fired.i know that we restrict it by using hierchy custom setting but how to do these please can any explain about it.
My trigger code is:
trigger duplicaterecord on Account (before insert) {
set<string>names=new set<string>();
List<Account>accs=[select id,name from account];
for(Account a:accs)
{
names.add(a.name);
}
for(account b:trigger.new)
{
if(names.contains(b.name))
{
b.addError('Duplicate Record');
}
}
}
My trigger code is:
trigger duplicaterecord on Account (before insert) {
set<string>names=new set<string>();
List<Account>accs=[select id,name from account];
for(Account a:accs)
{
names.add(a.name);
}
for(account b:trigger.new)
{
if(names.contains(b.name))
{
b.addError('Duplicate Record');
}
}
}
trigger duplicaterecord on Account (before insert) {
TriggerFlow__c triggerflow = TriggerFlow__c.getInstance(userinfo.getUserId()); // its profile Id or User Id. I am using logged user Id.
if(triggerflow.IsActive__c){
set<string>names=new set<string>();
List<Account>accs=[select id,name from account];
for(Account a:accs)
{
names.add(a.name);
}
for(account b:trigger.new)
{
if(names.contains(b.name))
{
b.addError('Duplicate Record');
}
}
}
}
All Answers
And create record Org level record as "IsActive=true"
And Create records with "IsActive=false" for whom you don't want to fire a trigger.
then your trigger will be
trigger duplicaterecord on Account (before insert) {
TriggerFlow__c triggerflow = TriggerFlow__c.getInstance(userinfo.getUserId()); // its profile Id or User Id. I am using logged user Id.
if(triggerflow.IsActive){
set<string>names=new set<string>();
List<Account>accs=[select id,name from account];
for(Account a:accs)
{
names.add(a.name);
}
for(account b:trigger.new)
{
if(names.contains(b.name))
{
b.addError('Duplicate Record');
}
}
}
}
in If condition used it if(triggerflow.isActive__c) insted of if(triggerflow.isActive)
trigger duplicaterecord on Account (before insert) {
TriggerFlow__c triggerflow = TriggerFlow__c.getInstance(userinfo.getUserId()); // its profile Id or User Id. I am using logged user Id.
if(triggerflow.IsActive__c){
set<string>names=new set<string>();
List<Account>accs=[select id,name from account];
for(Account a:accs)
{
names.add(a.name);
}
for(account b:trigger.new)
{
if(names.contains(b.name))
{
b.addError('Duplicate Record');
}
}
}
}
Thanks!
Thanks!