function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jaymin Sutarwala 7Jaymin Sutarwala 7 

How can i perform multiple transactions in a single test method in test class?

I have a written a trigger on Quote object which i am trying to test using a test class. I am using a static variable m_IsExecuting to make the trigger non-recursive; after the trigger runs the first time in a trasaction the static variable will be set to true so that the trigger won't run again in the same transaction. This is working fine when i test it using the SFDC user interface however it is causing a problem in my test class. I have written a @setup method in my test class where i am creating a Quote record which i am using in my testmethod. In my testmethod i have to update the quote record multiple time but after i perform the first update the static variable will be set to true and the trigger won't run for the subsequent updates. Is there any way where i can perform the update on the quote record in separate transactions in the same test method? 

trigger QuoteTracking on Quote (after insert, after update) {
    
    final string logTag = '[QuoteTracking]';
    List<Quote> newQTA = new List<Quote>();
    List<Quote> trackList = new List<Quote>();
    List<QTA__c> qtaUpdateList = new List<QTA__c>();
    Map<Id, QTA__c> recentQTAMap = new Map<Id,QTA__c>();
   
    if(QuoteTrackingHelper.getIsExecuting()){
        system.debug(logTag +'Currently executing. Exiting.');
        return;
    } 
    QuoteTrackingHelper.setIsExecuting(); 

   
SivaGSivaG
Hi Jaymin,

Since you are using the static variable to avoid non-recursive trigger execution, you can test the update only once. Maybe you should have multiple testmethods to test different scenarios on Quote object.

Thanks
Kumar