You need to sign in to do that
Don't have an account?
LoganUT
Test Class Not Covering Code List Query
Hello everyone!
I had this trigger and test class working well with 100% test coverage, then I added the Account__c field and now my test class is failing. The error I recieve is: System.QueryException: List has no rows for assignment to SObject.
I have tried writing my query as a list on the Location_Master__c section, but it still did not work. I have tried just about everythign I can think of..
Below I have included a section of my trigger and test class:
I had this trigger and test class working well with 100% test coverage, then I added the Account__c field and now my test class is failing. The error I recieve is: System.QueryException: List has no rows for assignment to SObject.
I have tried writing my query as a list on the Location_Master__c section, but it still did not work. I have tried just about everythign I can think of..
Below I have included a section of my trigger and test class:
trigger locStatusOpp on Opportunity (after update, after insert) { List<Location_Detail__c> loctoInsert = new List<Location_Detail__c>(); List<Location_Wait_List__c> loctoWaitInsert = new List<Location_Wait_List__c>(); List<Location_Master__c> locMaster = new List<Location_Master__c>(); for (Opportunity opp : Trigger.new) { if (opp.StageName == 'Closed Won' && opp.Location__c == 'Auburn Hills MI' && opp.Category__c != null && opp.Type_of_Charge__c == 'Subscription'){ Location_Master__c locAuburnHillsMI = [SELECT Id FROM Location_Master__c WHERE Name = 'Auburn Hills MI' LIMIT 1]; Location_Detail__c locNewAuburnHillsMI = new Location_Detail__c( Name = opp.Name, Account__c = opp.AccountId, Location__c = opp.Location__c, On_List__c = 1, Location_Master__c = locAuburnHillsMI.Id, Active__c = True, Vendor_Type__c = opp.Category__c); if(opp.Location__c == 'Auburn Hills MI'){ loctoInsert.add(locNewAuburnHillsMI); } }
@istest public class locStatusOppTEST { static testMethod void locStatusOppTEST1(){ List<Location_Detail__c> loctoInsert = new List<Location_Detail__c>(); Account acc = new Account(); acc.Name = 'Test'; insert acc; Location_Master__c locMaster = new Location_Master__c(); locMaster.Name = 'Auburn Hills MI'; insert locMaster; Opportunity opp = new Opportunity(); opp.Name = 'Test'; opp.AccountId = acc.Id; opp.Type_of_Charge__c = 'Subscription'; opp.Category__c = 'Cake Decorator'; opp.Location__c = 'Auburn Hills MI'; opp.StageName = 'Closed Won'; opp.CloseDate = date.newInstance(2017, 2, 20); insert opp; }
Then try below test class
Let us know if this will help you
The test class fails right away on Location_Detail__c.
Any other ideas?
Thanks!