You need to sign in to do that
Don't have an account?
Hughbert Strong
System.LimitException: SBQQ:Too many SOQL queries: 101Too many SOQL queries: 101
Hello,
My trigger is running fine in the sandbox. When I run my test class, I receive the following error: System.LimitException: SBQQ:Too many SOQL queries: 101. Can someone take a look at my code and point me in the right direction?
Trigger:
trigger QLAdjustListTotal on SBQQ__QuoteLine__c (after insert, after update, after delete) {
Decimal ADJrec = 0.00;
Decimal ADJup = 0.00;
Decimal ADJhware = 0.00;
Decimal NETrec = 0.00;
Decimal NETup = 0.00;
Decimal NEThware = 0.00;
String qid;
list<SBQQ__QuoteLine__c> l;
if(Trigger.isInsert || Trigger.isUpdate){
l = Trigger.new;
}
if(Trigger.isDelete){
l = Trigger.old;
}
try{
for(SBQQ__QuoteLine__c q : l){
qid=q.SBQQ__Quote__c;
}
for(SBQQ__QuoteLine__c f : l){
if(f.Adjusted_List_Line_Item__c > 0 && f.Quote_Line_Grouping__c == 'Recurring Fee'){
ADJrec+=f.Adjusted_List_Line_Item__c;
if(f.SBQQ__NetTotal__c > 0){
NETrec+=f.SBQQ__NetTotal__c;
}
}
if(f.Adjusted_List_Total__c > 0 && f.Quote_Line_Grouping__c == 'Upfront Fee'){
ADJup+=f.Adjusted_List_Total__c;
if(f.SBQQ__NetTotal__c > 0){
NETup+=f.SBQQ__NetTotal__c;
}
}
if(f.Adjusted_List_Total__c > 0 && f.Quote_Line_Grouping__c == 'Hardware'){
ADJhware+=f.Adjusted_List_Total__c;
if(f.SBQQ__NetTotal__c > 0){
NEThware+=f.SBQQ__NetTotal__c;
}
}
}
SBQQ__Quote__c q = [Select Id from SBQQ__Quote__c where Id =: qid];
q.Adjusted_List_Total_Recurring_Fee_2__c = ADJrec;
q.Adjusted_List_Total_Upfront_Fee_2__c = ADJup;
q.Adjusted_List_Total_Hardware_2__c = ADJhware;
q.Net_Total_Recurring_Fee_2__c = NETrec;
q.Net_Total_Upfront_Fee_2__c = NETup;
q.Net_Total_Hardware_2__c = NEThware;
update q;
}catch(QueryException ex){
System.debug(ADJrec);
System.debug(ADJup);
System.debug(ADJhware);
System.debug(NETrec);
System.debug(NETup);
System.debug(NEThware);}
}
Test Class
@isTest(SeeAllData = true)
public class TestQLAdjustListTotal {
static testMethod void TestQL(){
//Start Test
Test.startTest();
//Declare Variables and Objects
Decimal ST = 12;
Date StartQuote = Date.today();
Account a = new Account();
Opportunity o = new Opportunity();
SBQQ__Quote__c q = new SBQQ__Quote__c();
SBQQ__QuoteLine__c qlRec = new SBQQ__QuoteLine__c();
SBQQ__QuoteLine__c qlUp = new SBQQ__QuoteLine__c();
SBQQ__QuoteLine__c qlHware = new SBQQ__QuoteLine__c();
//Create Account Record
a.Name = 'TestAccount';
insert a;
update a;
//Create Opporunity
o.Name = 'Test Opp';
o.AccountId = a.Id;
o.Type = 'New Business 2';
o.CloseDate = StartQuote;
o.Type_of_Sale__c = 'New System';
o.ECi_Product__c = 'Spruce';
o.StageName = 'Owned Lead';
o.Cloud_Deal__c = True;
o.Pricebook2 = [Select id from Pricebook2 where id ='01s0v000000PRox'];
insert o;
//Create Quote Record
q.SBQQ__Account__c = a.Id;
q.SBQQ__Opportunity2__c = o.Id;
q.SBQQ__Status__c = 'Draft';
q.SBQQ__Type__c = 'Quote';
q.SBQQ__StartDate__c = StartQuote;
q.CurrencyIsoCode = 'USD';
q.SBQQ__Primary__c = True;
q.SBQQ__SubscriptionTerm__c = ST;
q.SBQQ__PriceBook__c = [Select id from Pricebook2 where id ='01s0v000000PRox'].id;
insert q;
//Create Quote Line Records
//Create Recurring Fee Quote Line
qlRec.SBQQ__Quote__c = q.Id;
qlRec.SBQQ__Product__c = [Select id from Product2 where id ='01t0v0000010bna'].id;
insert qlRec;
delete qlRec;
//Create Upfront Fee Quote Line
qlUp.SBQQ__Quote__c = q.Id;
qlUp.SBQQ__Product__c = [Select id from Product2 where id ='01t0v0000010bnV'].id;
insert qlUp;
delete qlUp;
//Create Hardware Fee Quote Line
qlHware.SBQQ__Quote__c = q.Id;
qlHware.SBQQ__Product__c = [Select id from Product2 where id ='01t0v0000010bnf'].id;
insert qlHware;
delete qlHware;
Test.stopTest();
}
}
My trigger is running fine in the sandbox. When I run my test class, I receive the following error: System.LimitException: SBQQ:Too many SOQL queries: 101. Can someone take a look at my code and point me in the right direction?
Trigger:
trigger QLAdjustListTotal on SBQQ__QuoteLine__c (after insert, after update, after delete) {
Decimal ADJrec = 0.00;
Decimal ADJup = 0.00;
Decimal ADJhware = 0.00;
Decimal NETrec = 0.00;
Decimal NETup = 0.00;
Decimal NEThware = 0.00;
String qid;
list<SBQQ__QuoteLine__c> l;
if(Trigger.isInsert || Trigger.isUpdate){
l = Trigger.new;
}
if(Trigger.isDelete){
l = Trigger.old;
}
try{
for(SBQQ__QuoteLine__c q : l){
qid=q.SBQQ__Quote__c;
}
for(SBQQ__QuoteLine__c f : l){
if(f.Adjusted_List_Line_Item__c > 0 && f.Quote_Line_Grouping__c == 'Recurring Fee'){
ADJrec+=f.Adjusted_List_Line_Item__c;
if(f.SBQQ__NetTotal__c > 0){
NETrec+=f.SBQQ__NetTotal__c;
}
}
if(f.Adjusted_List_Total__c > 0 && f.Quote_Line_Grouping__c == 'Upfront Fee'){
ADJup+=f.Adjusted_List_Total__c;
if(f.SBQQ__NetTotal__c > 0){
NETup+=f.SBQQ__NetTotal__c;
}
}
if(f.Adjusted_List_Total__c > 0 && f.Quote_Line_Grouping__c == 'Hardware'){
ADJhware+=f.Adjusted_List_Total__c;
if(f.SBQQ__NetTotal__c > 0){
NEThware+=f.SBQQ__NetTotal__c;
}
}
}
SBQQ__Quote__c q = [Select Id from SBQQ__Quote__c where Id =: qid];
q.Adjusted_List_Total_Recurring_Fee_2__c = ADJrec;
q.Adjusted_List_Total_Upfront_Fee_2__c = ADJup;
q.Adjusted_List_Total_Hardware_2__c = ADJhware;
q.Net_Total_Recurring_Fee_2__c = NETrec;
q.Net_Total_Upfront_Fee_2__c = NETup;
q.Net_Total_Hardware_2__c = NEThware;
update q;
}catch(QueryException ex){
System.debug(ADJrec);
System.debug(ADJup);
System.debug(ADJhware);
System.debug(NETrec);
System.debug(NETup);
System.debug(NEThware);}
}
Test Class
@isTest(SeeAllData = true)
public class TestQLAdjustListTotal {
static testMethod void TestQL(){
//Start Test
Test.startTest();
//Declare Variables and Objects
Decimal ST = 12;
Date StartQuote = Date.today();
Account a = new Account();
Opportunity o = new Opportunity();
SBQQ__Quote__c q = new SBQQ__Quote__c();
SBQQ__QuoteLine__c qlRec = new SBQQ__QuoteLine__c();
SBQQ__QuoteLine__c qlUp = new SBQQ__QuoteLine__c();
SBQQ__QuoteLine__c qlHware = new SBQQ__QuoteLine__c();
//Create Account Record
a.Name = 'TestAccount';
insert a;
update a;
//Create Opporunity
o.Name = 'Test Opp';
o.AccountId = a.Id;
o.Type = 'New Business 2';
o.CloseDate = StartQuote;
o.Type_of_Sale__c = 'New System';
o.ECi_Product__c = 'Spruce';
o.StageName = 'Owned Lead';
o.Cloud_Deal__c = True;
o.Pricebook2 = [Select id from Pricebook2 where id ='01s0v000000PRox'];
insert o;
//Create Quote Record
q.SBQQ__Account__c = a.Id;
q.SBQQ__Opportunity2__c = o.Id;
q.SBQQ__Status__c = 'Draft';
q.SBQQ__Type__c = 'Quote';
q.SBQQ__StartDate__c = StartQuote;
q.CurrencyIsoCode = 'USD';
q.SBQQ__Primary__c = True;
q.SBQQ__SubscriptionTerm__c = ST;
q.SBQQ__PriceBook__c = [Select id from Pricebook2 where id ='01s0v000000PRox'].id;
insert q;
//Create Quote Line Records
//Create Recurring Fee Quote Line
qlRec.SBQQ__Quote__c = q.Id;
qlRec.SBQQ__Product__c = [Select id from Product2 where id ='01t0v0000010bna'].id;
insert qlRec;
delete qlRec;
//Create Upfront Fee Quote Line
qlUp.SBQQ__Quote__c = q.Id;
qlUp.SBQQ__Product__c = [Select id from Product2 where id ='01t0v0000010bnV'].id;
insert qlUp;
delete qlUp;
//Create Hardware Fee Quote Line
qlHware.SBQQ__Quote__c = q.Id;
qlHware.SBQQ__Product__c = [Select id from Product2 where id ='01t0v0000010bnf'].id;
insert qlHware;
delete qlHware;
Test.stopTest();
}
}
1- Use SeeAllData = false
2- Create product as well
3- Use Test Class Property as shown in below code
refernce taken from
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_test.htm
I would suggest creating 6 test methods which ensures fresh governor limits instantiated using start and stop test for test scenario...for example:
Note: You might need to check your test debug logs to understand all 100+ SOQL queries if root cause is something else.
Let me know if this helps.