You need to sign in to do that
Don't have an account?
resetting a flag from true to false
I had a problem where my trigger was calling a class twice. To avoid the class from being called twice, i have created a Boolean Field is_class-called__c on the Object and setting it to 'True' in the trigger. This solves my problem for now, but I can sense some unforseen situations when the class won't be called when it should be because the flag is not reset to 'False'
How can i reset the flag to false?
if( trigger.isUpdate ){ list<Record__c> rs = new list<Record__c>(); rs = trigger.new; for( Record__c r :rs){ if( r.Status__c == 'Assigned' && r.Date__c==Date.today() && r.is_class_called__c == false ){ class.callMethod(r.Id, r.Status__c, UserInfo.getUserId(), 'New'); r.is_class_called__c = true; } }
We have found that there are times when we wish to bypass triggers, and have created a class to hold these static values.
Such as:
global static boolean AppointmentTrigger
{
get
{
if(AppointmentTrigger == null)
AppointmentTrigger = false;
return AppointmentTrigger;
}
set;
}
This value will always return false, in a single transaction because the static value is null, unless it is specifically set to true.
This is automatically reset in the next transaction.We maintain one class will a large number of these properties, and at the beginning of each trigger, we add the statement:
if(triggerBypass.AppointmentTrigger) return;
It works well for us.
All Answers
Hi,
Try to have the flag as a static boolean variable on the class itself, instead of using the custom field.
Thanks,
Anoop Asok
Thanks for the response. I ended up resetting the flag in a Workflow. However in future i must remember to handle it in the class as a static varaible.
If trigger is calling the class twice while it should only be called once, there is some logic issue here. I think it is better to identify the logic and fix it in trigger than handling inside the class. This will avoid any confusions lateron when that class is called from other part of the apex.
Thanks Santhosh Kumar.
We have found that there are times when we wish to bypass triggers, and have created a class to hold these static values.
Such as:
global static boolean AppointmentTrigger
{
get
{
if(AppointmentTrigger == null)
AppointmentTrigger = false;
return AppointmentTrigger;
}
set;
}
This value will always return false, in a single transaction because the static value is null, unless it is specifically set to true.
This is automatically reset in the next transaction.We maintain one class will a large number of these properties, and at the beginning of each trigger, we add the statement:
if(triggerBypass.AppointmentTrigger) return;
It works well for us.
Fabulous !!!! thanks a lot for sharing.