You need to sign in to do that
Don't have an account?
Kim Lebicz 2
List has no rows for assignment to sobject in Test Class with 2 tests
I have created a test class that runs 2 tests. The first test is successful but the second test fails. It give me this error, "System.QueryException: List has no rows for assignment to SObject" and references this line as the problem, "RecordType ort=[select Id from RecordType where SobjectType = 'Opportunity' and DeveloperName = 'SB_Process'];". I'm confused because both tests are the same so why would it work in one test but not the other?
I'm very new to this so any assistance is greatly appreciated.
I'm very new to this so any assistance is greatly appreciated.
Error Message - System.QueryException: List has no rows for assignment to SObject
Stack Trace - Class.ServiceFastQuoteControllerTest.testFastQuote2: line 58, column 1
@isTest
public class ServiceFastQuoteControllerTest {
static testMethod void testFastQuote1(){
Account a = new Account();
a.name = 'Test';
a.Street_Address_1__c = 'test';
a.City__c = 'test';
a.State_Providence__c = 'GA';
a.Zip_Postal_Code__c = '30240';
a.Cardiology_Account_Manager__c = UserInfo.getUserId();
insert a;
RecordType ort=[select Id from RecordType where SobjectType = 'Opportunity' and DeveloperName = 'CPQ_Service'];
Opportunity opp = new Opportunity();
opp.Name = 'Test';
opp.CloseDate = system.today();
opp.AccountId = a.Id;
opp.RecordTypeId = ort.Id;
opp.StageName = 'Qualification in Process';
insert opp;
/*
Test.startTest();
//PageReference pageRef = Page.FastQuoteOpp;
//Test.setCurrentPage(pageRef);
ApexPages.StandardController controller = new ApexPages.StandardController(opp);
FastQuoteController controllerext = new FastQuoteController(controller);
//PageReference pageRef = controllerext.OpenPage();
// System.assertEquals(controllerext.getFinishLocation().getUrl(), '/home/home.jsp');
// String curId = controllerext.getQuoteID();
// PageReference varQuoteId = controllerext.OpenPage();
Test.stopTest();*/
Test.StartTest();
PageReference pageRef = Page.FastQuoteOpp;
pageRef.getParameters().put('opportunityId', String.valueOf(opp.Id));
Test.setCurrentPage(pageRef);
ServiceFastQuoteController testFQ = new ServiceFastQuoteController(new ApexPages.StandardController(opp));
testFQ.OpenPage();
Test.StopTest();
}
static testMethod void testFastQuote2(){
Account a = new Account();
a.name = 'Test';
a.Street_Address_1__c = 'test';
a.City__c = 'test';
a.State_Providence__c = 'GA';
a.Zip_Postal_Code__c = '30240';
a.Cardiology_Account_Manager__c = UserInfo.getUserId();
insert a;
RecordType ort=[select Id from RecordType where SobjectType = 'Opportunity' and DeveloperName = 'CPQ_Service'];
Opportunity opp = new Opportunity();
opp.Name = 'Test';
opp.CloseDate = system.today();
opp.AccountId = a.Id;
opp.RecordTypeId = ort.Id;
opp.Quote_Expires_On__c = system.today();
opp.StageName = 'Qualification in Process';
insert opp;
/*
Test.startTest();
//PageReference pageRef = Page.FastQuoteOpp;
//Test.setCurrentPage(pageRef);
ApexPages.StandardController controller = new ApexPages.StandardController(opp);
FastQuoteController controllerext = new FastQuoteController(controller);
//PageReference pageRef = controllerext.OpenPage();
// System.assertEquals(controllerext.getFinishLocation().getUrl(), '/home/home.jsp');
// String curId = controllerext.getQuoteID();
// PageReference varQuoteId = controllerext.OpenPage();
Test.stopTest();*/
Test.StartTest();
PageReference pageRef = Page.FastQuoteOpp;
pageRef.getParameters().put('opportunityId', String.valueOf(opp.Id));
Test.setCurrentPage(pageRef);
ServiceFastQuoteController testFQ = new ServiceFastQuoteController(new ApexPages.StandardController(opp));
testFQ.OpenPage();
Test.StopTest();
}
}
ANd try this too
The second query returned all of the Opportunity recordtype ids