You need to sign in to do that
Don't have an account?
Tanyril
System.QueryException: List has no rows for assignment to SObject
System.QueryException: List has no rows for assignment to SObject | Class.ClientTransBatch.testBatch: line 132, column 1 |
Presumeably the only part of this code that matters is the test class at the very bottom.
That's the error I'm getting from the test in this class:
(Code removed)
I'm obviously doing something wrong with this test class but I can't figure out what. Can anyone help me?
well
if this is the statement in error, do you create any Contacts in the testmethod?
It looks like you are expecting Contacts to be already present. They won't be unless your testmethod uses @isTest(SeeAllData=true)
Using recordTypeIds hardcoded is very dangerous as they might not be the same between prod and sandbox. You should query the RecordType SObject first (using a recordTYpe Developer name as the key) to get the ID that you can use elsewhere . This way, you are protected between sandbox and prod
All Answers
well
if this is the statement in error, do you create any Contacts in the testmethod?
It looks like you are expecting Contacts to be already present. They won't be unless your testmethod uses @isTest(SeeAllData=true)
Using recordTypeIds hardcoded is very dangerous as they might not be the same between prod and sandbox. You should query the RecordType SObject first (using a recordTYpe Developer name as the key) to get the ID that you can use elsewhere . This way, you are protected between sandbox and prod
Hi,
A suggestion is to, Avoid using HardCoded Ids into the test methods. As Ids can be different in different environments(except Full copy sandbox and production org)
Create necessary test data into the test method.
For e.g.
@isTest
public static void testMethod(){
Account account = new Account(Name = 'Test Account');
insert account;
Contact contact = new Contact(AccountId= account.Id, LastName = 'TestLastName');
insert contact;
// Use the created data for further steps in test method
}
Hope this helps :)
THanks,
Devendra
Should have come back and told you that this was the hint I needed to get it all worked out. Thanks for your help!