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

Bypass validation rule
Hi
we have a validation rule on Lead object ,we need to make this validation rule as inactive like do not fire in the trigger which is on task object .the trigger is copying some field values from task to the lead object.
Thanka in advance
For example, you could create a hidden field called "bypass validation" that is reset after the lead is updated, then the validation rule could read something like:
AND(NOT(Bypass_Validation__c), YOUR_CRITERIA_HERE)
Hi sfdcfox,
Thanks for response, As per your idea i created a checkbox name(bypassvalidation__c) on lead object by default it is true, i have modified my validation rule as
AND(NOT(Bypass_Validation__c),AND(OwnerId <> $User.Id, $UserRole.Name ='Sales Rep'))
i have written a workflow rule to reset the field value to false to make the validation rule active from the UI,
Evaluation Criteria : Evaluate the rule when a record is created, and every time it’s edited .
Rule Criteria : Lead: Bypass ValidationEQUALSTrue
which will make the field value to false by field update action.
Here is my trigger :
trigger activitycall2 on task(after insert, after update) {
Set<id> leadIds = new set<id>(); // Lead container
task[] tasks = new task[0]; // matched tasks
id queueid,Id1;
UserRole[] roles;
Lead a;
// are there any leads?
for(task record:trigger.new) {
if( record.CallDurationInSeconds > 0 || record.whoid != null && record.whoid.getsobjecttype() == lead.sobjecttype ) {
leadids.add(record.whoid);
System.debug('size is'+leadIds.size());
tasks.add(record);
}
}
// if no leads, stop here
if(leadids.isempty()) {
return;
}
else {
// Gettting user Role
roles = [select id,name from userrole where id = :userinfo.getuserroleid()];
// does the queue exist, and what is the id?
for(group record:[select id from group where type = 'queue' and developername = 'Mailed_Data']) {
queueid = record.id;
}
List<Lead> ownerids=[select id ,ownerid from lead where ownerid = :queueid and id in :leadids];
if(ownerids.size()>0){
a = ownerids.get(0);
Id1=a.OwnerId;
System.debug(Id1);
}
// find any leads owned by the queue
leadids.retainall((new Map<id,lead>([select id from lead where ownerid = :queueid and id in :leadids])).keyset());
}
map<id,lead> leads = new map<id,lead>();
for(task record:tasks) {
if(Id1!=queueid){
leads.put(record.whoid,new lead(id=record.whoid,last_call_result__c=record.calldisposition, notes__c=record.Note_Summary__c, Bypass_Validation__c=True));
}
else{
leads.put(record.whoid,new lead(id=record.whoid,last_call_result__c=record.calldisposition, notes__c=record.Note_Summary__c, ownerid=userinfo.getuserid(), Bypass_Validation__c=True));
}
}
update leads.values();
}
=======================================================================================
In the above trigger please help out , how to bypass the validation rule.
Well the trigger may be prevented from executing a second time using Trigger Stopper (static variable)
Hi Sfdcfox,
could you please make the changes in the code(trigger) , I did'nt understand exactly.
Thanks.
Hi Sfdcfox,
Just a curious question, Can't we use Custom Settings into the validation rule and bypass the validation rule??
Will that cause any problem??
Thanks,
Devendra
i am confusing bypass validation rule.
Could you plz help on this.
Thanks in advance.
Regards,
SS