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

stop trigger firing twice
i have a trigger and trigger handler class as below and need to see how i can use a checkrecursive class to stop afterupdate code working twice
trigger........how do i reference the constants class into trigger
i thought
if(Trigger.isUpdate && Trigger.isAfter && constants.isfirsttime) but i need to add constants.isfirsttime = false
i dont know how to write this please help
checkrecursive class:
trigger........how do i reference the constants class into trigger
i thought
if(Trigger.isUpdate && Trigger.isAfter && constants.isfirsttime) but i need to add constants.isfirsttime = false
i dont know how to write this please help
trigger easycontacttrigger on Contact (before insert, after insert, before update, after update, before delete, after delete, after undelete){ if(Trigger.isUpdate && Trigger.isAfter){ easycontacttriggerhelper.sellercon(Trigger.new); /* easycontacttriggerhelper.buyerconConveyancy(Trigger.new, trigger.oldmap); easycontacttriggerhelper.buyerconMortgage(Trigger.new, trigger.oldmap); easycontacttriggerhelper.buyerconhomebuyerreport(Trigger.new, trigger.oldmap); easycontacttriggerhelper.buyerconutilityswitchgas(Trigger.new, trigger.oldmap); easycontacttriggerhelper.buyerconutilityswitchwater(Trigger.new, trigger.oldmap); easycontacttriggerhelper.buyerconutilityswitchelec(Trigger.new, trigger.oldmap); easycontacttriggerhelper.buyerconremovals(Trigger.new, trigger.oldmap); easycontacttriggerhelper.buyercongassafetycheck(Trigger.new, trigger.oldmap); easycontacttriggerhelper.buyerconpattest(Trigger.new, trigger.oldmap); easycontacttriggerhelper.buyerconaffiliates(Trigger.new, trigger.oldmap); */ }trigger handler class
public static void sellercon(list<Contact> cons) { list<Easy_Opportunity__c> opplist = new list <Easy_Opportunity__c>(); recordtype[] tt = [Select r.Id, r.SobjectType, r.Name From RecordType r where sobjecttype ='Easy_Opportunity__c' and Name = 'Residential Sales']; for(Contact con : cons){ if( con.Stage__c == 'Lead' && con.contacttype__c != null && con.contacttype__C.contains('Seller') ){ Easy_Opportunity__c newopp = new Easy_Opportunity__c (); newopp.ownerid = con.allocated_user__c; newopp.name = 'Market Appraisal'; newopp.account_name__c = con.accountid; newopp.CurrencyIsoCode = con.currencyisocode; newopp.stage__c = 'New'; newopp.recordtypeid = tt[0].Id; newopp.Contact_Name__c = con.id; newopp.Close_Date__c = Date.today().addDays(2); opplist.add(newopp); } } //outsideforloop // if(oppList.size() > 0){ insert opplist; list<Product__c> pdlist = new list <Product__c>(); recordtype[] aa = [Select r.Id, r.SobjectType, r.Name From RecordType r where sobjecttype ='Product__c' and Name = 'Residential Sales']; for(Easy_Opportunity__c eachopp:opplist){ Product__c newpd = new Product__c(); newpd.name = 'Market Appraisal'; newpd.Sale_Price__c = 0.00; newpd.recordtypeid = aa[0].id; newpd.Easy_Opportunity__c = eachopp.id; pdlist.add(newpd); } insert pdlist; } }
checkrecursive class:
public class Constants { public static final boolean isfirsttime = true; }
Seems like it is the updated version of code.
Anyways, you can add Constants.infirsttime = false in method.
-Thanks,
TK
PS: Please mark "BEST ANSWER" for the most helpful solution.
http://amitsalesforce.blogspot.in/2015/03/how-to-stop-recursive-trigger-in.html
you can create a class with a static Boolean variable with default value true. In the trigger, before executing your code keep a check that the variable is true or not. Once you check make the variable false.
Please let us know if this will help you
Final static variables can only be assigned in their declaration or in a static block
I put the } right at the end for
public static void sellercon2 (list<Contact> cons) {
if(Constants.isfirsttime){
Constants.isfirsttime = false;
all code
}