You need to sign in to do that
Don't have an account?
divya1234
System.AssertException: Assertion Failed: Delete failed. First exception on row 0 with id 00k0e00000f2t01AAA; first error: LIMIT_EXCEEDED, System.LimitException: Too many SOQL queries: 101: [] Stack trace: Class line 156, column 1
@isTest
private class optytst
{
static testMethod void optytstpositive()
{
TestHelper.createCustomSettings();
Map<String, Id> optyRTMap = RecordTypeUtilities.getRTMap('Opportunity');
List<OpportunityLineItem> oliList = new List<OpportunityLineItem>();
Id solId = Testfactory.createSolution('Test',
'Corporate Shared',
'Corporate',
'Mark Griffin',
'Larry Graubner');
Id prodId = Testfactory.createProduct('Claims',
'e-Services',
solId,
'Claims',
'e-Services Deafult');
Id pbId = Testfactory.createPricebook('Provider Complete');
Id beId = Testfactory.createPricebookEntry(prodId,
pbId);
Datetime timeStamp = Datetime.now();
Date closeDate = Date.today();
Account acct = new Account();
acct.Name = 'test Unit Test Account';
acct.Type = 'Provider';
acct.Federal_Tax_ID__c = '999887777';
acct.Integration_Id__c = 'SF_A99999999999';
acct.BillingStreet = '3055 Lebanon Pike';
acct.BillingCity = 'ville';
acct.BillingState = 'TN';
acct.BillingPostalCode = '37214';
insert acct;
Contact con = new Contact();
con.LastName = 'Test';
con.Title = 'VP';
con.AccountId = acct.Id;
con.Email = 'rater@sfdc.com';
insert con;
Campaign cmpn = new Campaign();
cmpn.Name = 'test Unit Test Campaign';
insert cmpn;
Opportunity opty = new Opportunity();
opty.RecordTypeId = optyRTMap.get('Provider Complete');
opty.Name = 'test Test Opty 1';
opty.AccountId = acct.Id;
opty.CloseDate = closeDate;
opty.StageName = '00 - Lead/Target';
opty.CampaignId = cmpn.Id;
opty.LeadSource = 'Self Generated Lead';
opty.Reason_Won_Lost__c = 'Other';
opty.Existing_Provider_Count__c = 10;
opty.Incentive__c = 'Retail Price Break';
opty.Incentive_Description__c = 'Test description';
opty.Live_Date__c = closeDate;
opty.Proposal_Expiration_Date__c = closeDate;
opty.Incentive_Providers__c = 10;
opty.Incentive_Deadline__c = closeDate;
insert opty;
OpportunityContactRole conRole = new OpportunityContactRole();
conRole.ContactId = con.Id;
conRole.OpportunityId = opty.Id;
conRole.Role = 'Executive';
insert conRole;
OpportunityLineItem oli = new OpportunityLineItem();
oli.OpportunityId = opty.Id;
oli.PricebookEntryId = beId;
oli.Quantity = 1;
oli.Sales_Type__c = 'New';
oli.Revenue_Type__c = 'Strategic';
oli.TotalPrice = 1000;
oliList.add(oli);
OpportunityLineItem oli2 = new OpportunityLineItem();
oli2.OpportunityId = opty.Id;
oli2.PricebookEntryId = beId;
oli2.Quantity = 1;
oli2.Sales_Type__c = 'New';
oli2.Revenue_Type__c = 'Strategic';
oli2.TotalPrice = 1000;
oli2.Project_Id__c = '1-234567890';
oliList.add(oli2);
insert oliList;
// set<ID> ids = Trigger.newMap.keyset();
PricebookEntry be = [SELECT Id,
IsActive
FROM PricebookEntry
WHERE Id = :beId];
be.IsActive = false;
update be;
try
{
delete oli;
}
catch (System.Dmlexception e)
{
System.assert(e.getMessage().contains('An Opportunity must have a product before it can be moved'),e.getMessage());
}
opty.Incentive__c = 'Other';
try
{
update opty;
}
catch (System.Dmlexception e)
{
System.assert(e.getMessage().contains('Incentive Description is required if Incentive = Other'),e.getMessage());
}
opty.StageName = '05 - Win';
try
{
update opty;
}
catch(System.Dmlexception e)
{
System.assert(e.getMessage().contains('is not an active product for pricebook.'),e.getMessage());
}
be.IsActive = true;
update be;
opty.Incentive__c = 'Retail Price Break';
opty.StageName = '05 - Win';
opty.Competitor__c = 'mc';
update opty;
try
{
delete oli2;
}
catch (System.Dmlexception e)
{
System.assert(e.getMessage().contains('Cannot delete Opportunity Products that are in the implementation phase.'),e.getMessage());
}
}
static testMethod void optyTestNegative()
{
TestHelper.createCustomSettings();
Map<String, Id> optyRTMap = RecordTypeUtilities.getRTMap('Opportunity');
Datetime timeStamp = Datetime.now();
Date closeDate = Date.today();
Campaign cmpn = new Campaign();
cmpn.Name = 'test Unit Test Campaign';
insert cmpn;
Account acct = new Account();
acct.Name = 'test Unit Test Account';
acct.Type = 'Provider';
acct.Federal_Tax_ID__c = '999887777';
acct.Integration_Id__c = 'SF_A99999999999';
acct.BillingStreet = '3055 Lebanon Pike';
acct.BillingCity = 'ville';
acct.BillingState = 'TN';
acct.BillingPostalCode = '37214';
insert acct;
Opportunity opty2 = new Opportunity();
opty2.RecordTypeId = optyRTMap.get('Provider Complete');
opty2.Name = 'test Test Opty 1';
opty2.AccountId = acct.Id;
opty2.CloseDate = closeDate;
opty2.StageName = '00 - Lead/Target';
opty2.CampaignId = cmpn.Id;
opty2.LeadSource = 'Self Generated Lead';
opty2.Reason_Won_Lost__c = 'Other';
opty2.Existing_Provider_Count__c = 10;
opty2.Incentive__c = 'Retail Price Break';
opty2.Incentive_Description__c = 'Test description';
opty2.Live_Date__c = closeDate;
opty2.Proposal_Expiration_Date__c = closeDate;
opty2.Incentive_Providers__c = 10;
opty2.Incentive_Deadline__c = closeDate;
try
{
insert opty2;
}
catch (System.Dmlexception e)
{
System.assert(e.getMessage().contains('Duplicate Opportunity names by Account are not allowed.'),e.getMessage());
}
Opportunity opty3 = new Opportunity();
opty3.RecordTypeId = optyRTMap.get('Provider Complete');
opty3.Name = 'test Test Opty 2';
opty3.AccountId = acct.Id;
opty3.CloseDate = closeDate;
opty3.StageName = '00 - Lead/Target';
opty3.CampaignId = cmpn.Id;
opty3.LeadSource = 'Self Generated Lead';
opty3.Reason_Won_Lost__c = 'Other';
opty3.Existing_Provider_Count__c = 10;
opty3.Incentive__c = 'Retail Price Break';
opty3.Incentive_Description__c = 'Test description';
opty3.Live_Date__c = closeDate;
opty3.Proposal_Expiration_Date__c = closeDate;
opty3.Incentive_Providers__c = 10;
opty3.Incentive_Deadline__c = closeDate;
insert opty3;
opty3.Name = 'test Test Opty 1';
try
{
update opty3;
}
catch (System.Dmlexception e)
{
System.assert(e.getMessage().contains('Duplicate Opportunity names by Account are not allowed.'),e.getMessage());
}
Opportunity opty4 = new Opportunity();
opty4.RecordTypeId = optyRTMap.get('Provider Complete');
opty4.Name = 'test Test Opty 3';
opty4.AccountId = acct.Id;
opty4.CloseDate = closeDate;
opty4.StageName = '05 - Win';
opty4.CampaignId = cmpn.Id;
opty4.LeadSource = 'Self Generated Lead';
opty4.Reason_Won_Lost__c = 'Other';
opty4.Existing_Provider_Count__c = 10;
opty4.Incentive__c = 'Retail Price Break';
opty4.Incentive_Description__c = 'Test description';
opty4.Live_Date__c = closeDate;
opty4.Proposal_Expiration_Date__c = closeDate;
opty4.Incentive_Providers__c = 10;
opty4.Incentive_Deadline__c = closeDate;
try
{
insert opty4;
}
catch (System.Dmlexception e)
{
System.assert(e.getMessage().contains('Closing Stage not allowed at Opportunity creation. ' +
'You must update the stage after a product is added. ' +
'(PreventNewClosingOptyBI.trigger)'),e.getMessage());
}
}
static testMethod void testThresholdHandler()
{
Set<String> statuses = new set<String>{'Open', 'Responded', 'Reparation'};
Set<String> priorities = new set<String>{'SLA 1', 'SLA 2', 'SLA 3'};
Set<String> origins = new set<String>{'Email', 'Web', 'Phone'};
for (String p : priorities)
for (String o : origins)
for (String s : statuses)
CaseSLAThresholdHandler.getThresholds(new Case(Priority=p, Origin=o, Status=s));
// Test unknown case.
CaseSLAThresholdHandler.getThresholds(new Case(Priority='Hi', Origin='Hi', Status='Hi'));
}
static testMethod void testTrigger()
{
Case c = new Case(Priority='SLA 1', Origin='Web', Status='Responded');
insert c;
c.Status = 'Open';
update c;
c.Priority = 'SLA 4';
update c;
}
static testMethod void testSLAController()
{
Case c = new Case(Priority='SLA 1', Origin='Web', Status='Responded', Last_Status_Change__c=System.now());
insert c;
ApexPages.StandardController caseController = new ApexPages.StandardController(c);
CaseSLAController slaController = new CaseSLAController(caseController);
slaController.getIsWithin();
slaController.getDuration();
slaController.getSlaUrl();
}
static testMethod void testSLAListController()
{
List<Case> cList = new List<Case>();
cList.add(new Case(Priority='SLA 1', Origin='Web', Status='Responded', Last_Status_Change__c=System.now()));
cList.add(new Case(Priority='SLA 1', Origin='Web', Status='Open'));
cList.add(new Case(Priority='SLA 1', Origin='Web', Status='Open'));
cList.add(new Case(Priority='SLA 1', Origin='Web', Status='Open'));
insert cList;
cList[1].Last_Status_Change__c = System.now().addSeconds(-120);
cList[2].Last_Status_Change__c = System.now().addSeconds(-90);
update cList;
CaseSLAListController slaListController = new CaseSLAListController();
slaListController.getIsWithin();
}
private class optytst
{
static testMethod void optytstpositive()
{
TestHelper.createCustomSettings();
Map<String, Id> optyRTMap = RecordTypeUtilities.getRTMap('Opportunity');
List<OpportunityLineItem> oliList = new List<OpportunityLineItem>();
Id solId = Testfactory.createSolution('Test',
'Corporate Shared',
'Corporate',
'Mark Griffin',
'Larry Graubner');
Id prodId = Testfactory.createProduct('Claims',
'e-Services',
solId,
'Claims',
'e-Services Deafult');
Id pbId = Testfactory.createPricebook('Provider Complete');
Id beId = Testfactory.createPricebookEntry(prodId,
pbId);
Datetime timeStamp = Datetime.now();
Date closeDate = Date.today();
Account acct = new Account();
acct.Name = 'test Unit Test Account';
acct.Type = 'Provider';
acct.Federal_Tax_ID__c = '999887777';
acct.Integration_Id__c = 'SF_A99999999999';
acct.BillingStreet = '3055 Lebanon Pike';
acct.BillingCity = 'ville';
acct.BillingState = 'TN';
acct.BillingPostalCode = '37214';
insert acct;
Contact con = new Contact();
con.LastName = 'Test';
con.Title = 'VP';
con.AccountId = acct.Id;
con.Email = 'rater@sfdc.com';
insert con;
Campaign cmpn = new Campaign();
cmpn.Name = 'test Unit Test Campaign';
insert cmpn;
Opportunity opty = new Opportunity();
opty.RecordTypeId = optyRTMap.get('Provider Complete');
opty.Name = 'test Test Opty 1';
opty.AccountId = acct.Id;
opty.CloseDate = closeDate;
opty.StageName = '00 - Lead/Target';
opty.CampaignId = cmpn.Id;
opty.LeadSource = 'Self Generated Lead';
opty.Reason_Won_Lost__c = 'Other';
opty.Existing_Provider_Count__c = 10;
opty.Incentive__c = 'Retail Price Break';
opty.Incentive_Description__c = 'Test description';
opty.Live_Date__c = closeDate;
opty.Proposal_Expiration_Date__c = closeDate;
opty.Incentive_Providers__c = 10;
opty.Incentive_Deadline__c = closeDate;
insert opty;
OpportunityContactRole conRole = new OpportunityContactRole();
conRole.ContactId = con.Id;
conRole.OpportunityId = opty.Id;
conRole.Role = 'Executive';
insert conRole;
OpportunityLineItem oli = new OpportunityLineItem();
oli.OpportunityId = opty.Id;
oli.PricebookEntryId = beId;
oli.Quantity = 1;
oli.Sales_Type__c = 'New';
oli.Revenue_Type__c = 'Strategic';
oli.TotalPrice = 1000;
oliList.add(oli);
OpportunityLineItem oli2 = new OpportunityLineItem();
oli2.OpportunityId = opty.Id;
oli2.PricebookEntryId = beId;
oli2.Quantity = 1;
oli2.Sales_Type__c = 'New';
oli2.Revenue_Type__c = 'Strategic';
oli2.TotalPrice = 1000;
oli2.Project_Id__c = '1-234567890';
oliList.add(oli2);
insert oliList;
// set<ID> ids = Trigger.newMap.keyset();
PricebookEntry be = [SELECT Id,
IsActive
FROM PricebookEntry
WHERE Id = :beId];
be.IsActive = false;
update be;
try
{
delete oli;
}
catch (System.Dmlexception e)
{
System.assert(e.getMessage().contains('An Opportunity must have a product before it can be moved'),e.getMessage());
}
opty.Incentive__c = 'Other';
try
{
update opty;
}
catch (System.Dmlexception e)
{
System.assert(e.getMessage().contains('Incentive Description is required if Incentive = Other'),e.getMessage());
}
opty.StageName = '05 - Win';
try
{
update opty;
}
catch(System.Dmlexception e)
{
System.assert(e.getMessage().contains('is not an active product for pricebook.'),e.getMessage());
}
be.IsActive = true;
update be;
opty.Incentive__c = 'Retail Price Break';
opty.StageName = '05 - Win';
opty.Competitor__c = 'mc';
update opty;
try
{
delete oli2;
}
catch (System.Dmlexception e)
{
System.assert(e.getMessage().contains('Cannot delete Opportunity Products that are in the implementation phase.'),e.getMessage());
}
}
static testMethod void optyTestNegative()
{
TestHelper.createCustomSettings();
Map<String, Id> optyRTMap = RecordTypeUtilities.getRTMap('Opportunity');
Datetime timeStamp = Datetime.now();
Date closeDate = Date.today();
Campaign cmpn = new Campaign();
cmpn.Name = 'test Unit Test Campaign';
insert cmpn;
Account acct = new Account();
acct.Name = 'test Unit Test Account';
acct.Type = 'Provider';
acct.Federal_Tax_ID__c = '999887777';
acct.Integration_Id__c = 'SF_A99999999999';
acct.BillingStreet = '3055 Lebanon Pike';
acct.BillingCity = 'ville';
acct.BillingState = 'TN';
acct.BillingPostalCode = '37214';
insert acct;
Opportunity opty2 = new Opportunity();
opty2.RecordTypeId = optyRTMap.get('Provider Complete');
opty2.Name = 'test Test Opty 1';
opty2.AccountId = acct.Id;
opty2.CloseDate = closeDate;
opty2.StageName = '00 - Lead/Target';
opty2.CampaignId = cmpn.Id;
opty2.LeadSource = 'Self Generated Lead';
opty2.Reason_Won_Lost__c = 'Other';
opty2.Existing_Provider_Count__c = 10;
opty2.Incentive__c = 'Retail Price Break';
opty2.Incentive_Description__c = 'Test description';
opty2.Live_Date__c = closeDate;
opty2.Proposal_Expiration_Date__c = closeDate;
opty2.Incentive_Providers__c = 10;
opty2.Incentive_Deadline__c = closeDate;
try
{
insert opty2;
}
catch (System.Dmlexception e)
{
System.assert(e.getMessage().contains('Duplicate Opportunity names by Account are not allowed.'),e.getMessage());
}
Opportunity opty3 = new Opportunity();
opty3.RecordTypeId = optyRTMap.get('Provider Complete');
opty3.Name = 'test Test Opty 2';
opty3.AccountId = acct.Id;
opty3.CloseDate = closeDate;
opty3.StageName = '00 - Lead/Target';
opty3.CampaignId = cmpn.Id;
opty3.LeadSource = 'Self Generated Lead';
opty3.Reason_Won_Lost__c = 'Other';
opty3.Existing_Provider_Count__c = 10;
opty3.Incentive__c = 'Retail Price Break';
opty3.Incentive_Description__c = 'Test description';
opty3.Live_Date__c = closeDate;
opty3.Proposal_Expiration_Date__c = closeDate;
opty3.Incentive_Providers__c = 10;
opty3.Incentive_Deadline__c = closeDate;
insert opty3;
opty3.Name = 'test Test Opty 1';
try
{
update opty3;
}
catch (System.Dmlexception e)
{
System.assert(e.getMessage().contains('Duplicate Opportunity names by Account are not allowed.'),e.getMessage());
}
Opportunity opty4 = new Opportunity();
opty4.RecordTypeId = optyRTMap.get('Provider Complete');
opty4.Name = 'test Test Opty 3';
opty4.AccountId = acct.Id;
opty4.CloseDate = closeDate;
opty4.StageName = '05 - Win';
opty4.CampaignId = cmpn.Id;
opty4.LeadSource = 'Self Generated Lead';
opty4.Reason_Won_Lost__c = 'Other';
opty4.Existing_Provider_Count__c = 10;
opty4.Incentive__c = 'Retail Price Break';
opty4.Incentive_Description__c = 'Test description';
opty4.Live_Date__c = closeDate;
opty4.Proposal_Expiration_Date__c = closeDate;
opty4.Incentive_Providers__c = 10;
opty4.Incentive_Deadline__c = closeDate;
try
{
insert opty4;
}
catch (System.Dmlexception e)
{
System.assert(e.getMessage().contains('Closing Stage not allowed at Opportunity creation. ' +
'You must update the stage after a product is added. ' +
'(PreventNewClosingOptyBI.trigger)'),e.getMessage());
}
}
static testMethod void testThresholdHandler()
{
Set<String> statuses = new set<String>{'Open', 'Responded', 'Reparation'};
Set<String> priorities = new set<String>{'SLA 1', 'SLA 2', 'SLA 3'};
Set<String> origins = new set<String>{'Email', 'Web', 'Phone'};
for (String p : priorities)
for (String o : origins)
for (String s : statuses)
CaseSLAThresholdHandler.getThresholds(new Case(Priority=p, Origin=o, Status=s));
// Test unknown case.
CaseSLAThresholdHandler.getThresholds(new Case(Priority='Hi', Origin='Hi', Status='Hi'));
}
static testMethod void testTrigger()
{
Case c = new Case(Priority='SLA 1', Origin='Web', Status='Responded');
insert c;
c.Status = 'Open';
update c;
c.Priority = 'SLA 4';
update c;
}
static testMethod void testSLAController()
{
Case c = new Case(Priority='SLA 1', Origin='Web', Status='Responded', Last_Status_Change__c=System.now());
insert c;
ApexPages.StandardController caseController = new ApexPages.StandardController(c);
CaseSLAController slaController = new CaseSLAController(caseController);
slaController.getIsWithin();
slaController.getDuration();
slaController.getSlaUrl();
}
static testMethod void testSLAListController()
{
List<Case> cList = new List<Case>();
cList.add(new Case(Priority='SLA 1', Origin='Web', Status='Responded', Last_Status_Change__c=System.now()));
cList.add(new Case(Priority='SLA 1', Origin='Web', Status='Open'));
cList.add(new Case(Priority='SLA 1', Origin='Web', Status='Open'));
cList.add(new Case(Priority='SLA 1', Origin='Web', Status='Open'));
insert cList;
cList[1].Last_Status_Change__c = System.now().addSeconds(-120);
cList[2].Last_Status_Change__c = System.now().addSeconds(-90);
update cList;
CaseSLAListController slaListController = new CaseSLAListController();
slaListController.getIsWithin();
}
At line 156 you are asserting:
Which appears to be checking that the try/catch block throws an exception - I'm guessing from a trigger that checks the Stage of an Opportunity.
But in that trigger you must be running a SOQL query (in a loop) and so instead, it is processing over 100 database queries, which is not allowed and is thus throwing a different exception first.
You will need to look in the delete trigger on Opportunity and fix the problem with SOQL queries.
What a great example of a working unit test though! I love it when tests actually highlight problems with changed code.
The delete try/catch block is on OpportunityLineItem
It's really hard reading pasted code like that! If you use the formatting icon in the toolbar (which has the angle brackets < > in it) it will format the code nicely and give colours/line numbers etc.
Though it also won't save/compile as there is a random dot inside your if brackets, which makes me think perhaps some code has been removed?!
;)