Chained Queueable Job Transaction Limits

If we call one Queueable class from another Queueable Class then we call that as chaining. For each Queueable class, Salesforce will reset the Governor limits. I tried to prove this using below code snippet  :

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
public class QueueableExample1 implements Queueable
{
    public void execute(QueueableContext context) 
    {
        System.debug('-IN--QueueableExample1---Before limits---- '+Limits.getLimitQueries());    
        System.debug('-IN--QueueableExample1---Before limits---- '+Limits.getQueries());  
        
        List<Account> accList = [Select Id,Name from Account];
        System.debug('-IN--QueueableExample1---After limits---- '+Limits.getLimitQueries());    
        System.debug('-IN--QueueableExample1---After limits---- '+Limits.getQueries()); 
        
        System.enqueueJob(new QueueableExample2());
    }
}

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
public class QueueableExample2 implements Queueable
{
    public void execute(QueueableContext context) 
    {
        System.debug('-IN--QueueableExample2---Before limits---- '+Limits.getLimitQueries());    
        System.debug('-IN--QueueableExample2---Before limits---- '+Limits.getQueries());  
        
        List<Account> accList = [Select Id,Name from Account];
        System.debug('-IN--QueueableExample2---After limits---- '+Limits.getLimitQueries());    
        System.debug('-IN--QueueableExample2---After limits---- '+Limits.getQueries()); 
        
    }
}
To initiate the above class, Open "execute anonymous window" & execute the below code snippet :
1
System.enqueueJob(new QueueableExample1());

Here is the output :
1
2
3
4
5
6
7
8
9
-IN--QueueableExample1---Before limits---- 200
-IN--QueueableExample1---Before limits---- 0
-IN--QueueableExample1---After limits---- 200
-IN--QueueableExample1---After limits---- 1

-IN--QueueableExample2---Before limits---- 200
-IN--QueueableExample2---Before limits---- 0
-IN--QueueableExample2---After limits---- 200
-IN--QueueableExample2---After limits---- 1

Benefits/Points to be noted about Queueable Jobs:
1. The class execution will start from left to right. So, the leftmost class will be called(/executed) first and so on.
2. For each Queueable class execution, a separate debug log will be created.
3. Only after completion of the first Queueable class then only next class will enter into Queue. The below diagrams depicts the same :

 tHiNk gooD and dO thE bEsT.........MANJU NATH 🌝

Comments