You need to sign in to do that
Don't have an account?
selva kumar 14
Testcase execution error in sandbox
Hi Everyone,
I have executed a test case in sandbox. But it throws the follwoing error.
Error:
System.QueryException: List has no rows for assignment to SObject
Stack Trace:
Class.TestBulkPricebookOpp.validatepric: line 6, column 1
I couldn't able to resolve it. My test class coding is given below.
@isTest
public class TestBulkPricebookOpp {
Public static testmethod void validatepric(){
Id pbID = null;
pbID = [Select Name, Description From Pricebook2 where Name = 'Bulk Price Book'].Id;
List<RecordType> recordtypId = [Select SobjectType, Name, Id, DeveloperName From RecordType Where SobjectType = 'Opportunity' And Name = 'k) Bulk Services'];
Account obj = new Account( Name = 'Test', Zip_Code__c='29801');
insert obj;
Opportunity objOpp = new Opportunity(Name = 'newTest',recordtypeId=recordtypId[0].Id,AccountId = obj.Id,StageName ='Prospecting',CloseDate=Date.today());
objOpp.Pricebook2Id=pbID;
insert objOpp;
Opportunity objUOppt = new opportunity(Id =objOpp.Id );
update objUOppt ;
}
}
Please any one correct me in the coding part. Thanks in advance.
I have executed a test case in sandbox. But it throws the follwoing error.
Error:
System.QueryException: List has no rows for assignment to SObject
Stack Trace:
Class.TestBulkPricebookOpp.validatepric: line 6, column 1
I couldn't able to resolve it. My test class coding is given below.
@isTest
public class TestBulkPricebookOpp {
Public static testmethod void validatepric(){
Id pbID = null;
pbID = [Select Name, Description From Pricebook2 where Name = 'Bulk Price Book'].Id;
List<RecordType> recordtypId = [Select SobjectType, Name, Id, DeveloperName From RecordType Where SobjectType = 'Opportunity' And Name = 'k) Bulk Services'];
Account obj = new Account( Name = 'Test', Zip_Code__c='29801');
insert obj;
Opportunity objOpp = new Opportunity(Name = 'newTest',recordtypeId=recordtypId[0].Id,AccountId = obj.Id,StageName ='Prospecting',CloseDate=Date.today());
objOpp.Pricebook2Id=pbID;
insert objOpp;
Opportunity objUOppt = new opportunity(Id =objOpp.Id );
update objUOppt ;
}
}
Please any one correct me in the coding part. Thanks in advance.
@isTest (SeeAllData == true)
public class TestBulkPricebookOpp {
Public static testmethod void validatepric(){
Id pbID = null;
pbID = [Select Name, Description From Pricebook2 where Name = 'Bulk Price Book'].Id;
List<RecordType> recordtypId = [Select SobjectType, Name, Id, DeveloperName From RecordType Where SobjectType = 'Opportunity' And Name = 'k) Bulk Services'];
Account obj = new Account( Name = 'Test', Zip_Code__c='29801');
insert obj;
Opportunity objOpp = new Opportunity(Name = 'newTest',recordtypeId=recordtypId[0].Id,AccountId = obj.Id,StageName ='Prospecting',CloseDate=Date.today());
objOpp.Pricebook2Id=pbID;
insert objOpp;
Opportunity objUOppt = new opportunity(Id =objOpp.Id );
update objUOppt ;
}
}
All Answers
@isTest (SeeAllData == true)
public class TestBulkPricebookOpp {
Public static testmethod void validatepric(){
Id pbID = null;
pbID = [Select Name, Description From Pricebook2 where Name = 'Bulk Price Book'].Id;
List<RecordType> recordtypId = [Select SobjectType, Name, Id, DeveloperName From RecordType Where SobjectType = 'Opportunity' And Name = 'k) Bulk Services'];
Account obj = new Account( Name = 'Test', Zip_Code__c='29801');
insert obj;
Opportunity objOpp = new Opportunity(Name = 'newTest',recordtypeId=recordtypId[0].Id,AccountId = obj.Id,StageName ='Prospecting',CloseDate=Date.today());
objOpp.Pricebook2Id=pbID;
insert objOpp;
Opportunity objUOppt = new opportunity(Id =objOpp.Id );
update objUOppt ;
}
}
Please follow below link it will help
.https://developer.salesforce.com/forums/ForumsMain?id=906F0000000BChFIAW
Test case is working fine.
I have corrected my test case.