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
Paula MenendezPaula Menendez 

CPQ Renewal Automation Error: 'SBQQ:Too many queueable jobs added to the queue: 2

Hi,
I am having this error:
FATAL_ERROR System.LimitException: SBQQ:Too many queueable jobs added to the queue: 2
when I deploy the automation of the Renewal process (I have tried  with batch size = 1,batch size = 50 and batch size = 200 nothing works ) in production (works in Sandbox), even though I have followed this article and almost have copied the batch apex class that appears in this Knowledge article: https://help.salesforce.com/articleView?id=000267468&language=en_US&type=1 .

Below is my batch apex class.The main difference to the one in the Knowledge article mentioned before is the Query at the 'start()' method, see below:
 
///***Batch Apex Class***

global class Renewal implements Database.Batchable<SObject>, Database.Stateful {
	global Integer recordsProcessed = 0;

	global Database.QueryLocator start(Database.BatchableContext bc){
		return Database.getQueryLocator(
			//This is where you input the conditions for the records which you wish to set renewal for 
			'SELECT SBQQ__RenewalForecast__c, Id FROM Contract WHERE SBQQ__RenewalForecast__c = false AND EndDate=NEXT_N_QUARTERS:2');
	}
	global void execute(Database.BatchableContext bc, List<Contract> scope){
		for(Contract contract: scope){    
            System.debug('<DEBUG> Update Renewal Forecast and Quoted for Contract: '+ contract.Id);
			contract.SBQQ__RenewalForecast__c = true;
	
			recordsProcessed = recordsProcessed + 1;

		}
        update scope;
        
        
	}
    
	global void finish(Database.BatchableContext bc){
       // Get the ID of the AsyncApexJob representing this batch job
       // from Database.BatchableContext.
       // Query the AsyncApexJob object to retrieve the current job's information.
       AsyncApexJob a = [SELECT Id, Status, NumberOfErrors, JobItemsProcessed,TotalJobItems, CreatedBy.Email FROM AsyncApexJob WHERE Id =:BC.getJobId()];

       // OPTIONAL: Send an email to the Apex job's submitter notifying of job completion.
       Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
       String[] toAddresses = new String[] {a.CreatedBy.Email};
       mail.setToAddresses(toAddresses);
       mail.setSubject('Contract Renewal Batch ' + a.Status);
       mail.setPlainTextBody
       ('The batch Apex job processed ' + a.TotalJobItems +
       ' batches with '+ a.NumberOfErrors + ' failures.');
       Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
    }
}
This is the test class for this batch apex class, although I don't think it has any relation to the problem:
@isTest 
public class RenewalTest {
    public static testMethod void testRenewal() {
        
        // Create an Account
        Account ac = new Account();
        ac.Name = 'Jamones Corporation Number';
        ac.Type = 'Manufacturer';
        ac.Industry = 'Food';
        ac.Tiering__c = 'Tier-1';
        ac.Language__c = 'Spanish';
        insert ac;
        
        // Create an Opportunity
        Opportunity op = new Opportunity();
        op.Name= 'OriginalOpNumber';
        op.AccountId = ac.Id;
        op.Type = 'New business';
        op.StageName = 'A - Interest';
        op.CloseDate = Date.today();
        insert op;
                
        // Create the Contract
        Contract c = new Contract();
        c.StartDate = Date.today().addMonths(-8);
        c.ContractTerm = 12;
        //c.EndDate = c.StartDate.addMonths(c.ContractTerm);
        c.Status = 'draft';
        c.AccountId = ac.Id;        
        c.SBQQ__Opportunity__c = op.Id;
        c.SBQQ__RenewalForecast__c = false;
        //c.SBQQ__RenewalQuoted__c = false;
        insert c;
         
       	System.debug('<DEBUG> Contract Id:'+ String.valueOf(c.Id));
        System.debug('<DEBUG> Date of today:'+ String.valueOf(Date.today()));
        System.debug('<DEBUG> Contract Start Date:'+ String.valueOf(c.StartDate));
        System.debug('<DEBUG> Contract End Date:'+ String.valueOf(c.EndDate));
        System.debug('<DEBUG> Contract Renewal Forecast:'+ String.valueOf(c.SBQQ__RenewalForecast__c));
        //System.debug('<DEBUG> Contract Renewal Quoted:'+ String.valueOf(c.SBQQ__RenewalQuoted__c));
        
        Test.startTest();

        Renewal obj = new Renewal();
        DataBase.executeBatch(obj);
        
        Test.stopTest();
        
        Contract contract = [SELECT SBQQ__RenewalForecast__c FROM Contract WHERE Id= :c.Id];
        System.assertEquals(true, contract.SBQQ__RenewalForecast__c );
        //System.assertEquals(true, contract.SBQQ__RenewalQuoted__c ); 
    	System.debug('<DEBUG> Contract Renewal Forcast:'+ contract.SBQQ__RenewalForecast__c);
        //System.debug('<DEBUG> Contract Renewal Forcast:'+ contract.SBQQ__RenewalQuoted__c );
      }            
}

I am pretty new to salesforce but after analizing the logs the only thing that is bothering me is that there are some triggers in the Opportunity that seem to be called very frequently, and I have a suspicion they might me not 'bulkified'? However the trigger i am talking about is part of the Salesforce package 'Declarative Rollup Summary' and therefore I cannot see this part of code, so I have no idea how the triggers of this package work. See screenshots below:
User-added image
User-added image

Can anyone tell me if the fact that these triggers are called constantly is normal or not? And more importnaly, does anyone have any idea of what could be happening?

I can post more information if neeeded. 
Thanks in advance!!
Saravanan @CreationSaravanan @Creation
Hi Paula,

Please post you Scheduler Class. I hope something wron in the scheduler.

Regards,
James Allen 4James Allen 4
Hi,  Were you able to find out why you were getting this error?  I am trying to implement the same code and I am getting the same error in my sandbox.  It works if I update a field other than the Renewal Forecast.  So like you I would assume it is a trigger in the SBQQ package that is causing the problem.
Manjunath S 75Manjunath S 75
Old thread but found this:

@James
Too Many Queueable Jobs error in the Salesforce CPQ Package
https://help.salesforce.com/articleView?id=000269746&language=en_US&type=1

Looks like the issue is seen when Renewal Forecast is set to TRUE.