You need to sign in to do that
Don't have an account?

Help with Test Class Error – System.QueryException: List has no rows for assignment to SObject
Hi,
Could someone help me get past this error for the test class below?
System.QueryException: List has no rows for assignment to SObject
Class.AccountTerritoryManagementTest.validateTerritoryManagement: line 13, column 1
Thank you!
Could someone help me get past this error for the test class below?
System.QueryException: List has no rows for assignment to SObject
Class.AccountTerritoryManagementTest.validateTerritoryManagement: line 13, column 1
@isTest private class AccountTerritoryManagementTest { static testMethod void validateTerritoryManagement() { Account a = new Account(Name='Territory Testing', BillingState='LA', BillingPostalCode='12345', Account_Territory__c = null); System.debug('Territory = ' + a.Account_Territory__c); insert a; a = [SELECT Account_Territory__c, BillingPostalCode FROM Account WHERE Id =:a.Id]; Zip_Code__c zipCode = [Select Name, Territory__c from Zip_Code__c where Name =:a.BillingPostalCode]; System.debug('Territory after trigger fired: ' + a.Account_Territory__c); System.assertEquals(zipCode.Territory__c, a.Account_Territory__c); } }I want to deploy a new apex class to Production, but I'm having issues because its test class keeping failing. Any advice or insight would be greatly appreciated.
Thank you!
Hope it helps and it solves the puzzle then please mark it as best answer!
if this helpss to resolve your issue, please choose this as best answer.
Thank you!
Does this mean I also need to insert a Territory record since Territory__c on Zip_Code__c is a Territory lookup field? Because I am now receiving the following error:
Class.AccountTerritoryManagementTest.validateTerritoryManagement: line 11, column 1
let me know if you have any other questions thank you!