You need to sign in to do that
Don't have an account?
Mike Parks 5
I've written a simple trigger which works fine in Sandbox. However my test class won't work at all and so I am unable to move my trigger into Production. I keep getting the error: "List has no rows for assignment to SObject" on the line Insert prj; in the test class shown below. I'm worried the SObject prj is empty because it requires a RecordType and I'm not creating/setting the RecordType correctly. All of the other Insert's in the Test Class work fine but they don't require RecordType.
Here's my Test Class so far.....
Error: List has no rows for assignment to SObject in test class for a simple Trigger
I've written a simple trigger which works fine in Sandbox. However my test class won't work at all and so I am unable to move my trigger into Production. I keep getting the error: "List has no rows for assignment to SObject" on the line Insert prj; in the test class shown below. I'm worried the SObject prj is empty because it requires a RecordType and I'm not creating/setting the RecordType correctly. All of the other Insert's in the Test Class work fine but they don't require RecordType.
trigger UpdateRelatedGoal on Project__c (before insert) { for (Project__c p : Trigger.New) { if(p.Start_Date_Project__c==Null ) { ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please enter a Project Start Date')); } sObject s = [SELECT Id FROM Goals__c WHERE Region_Name__c =:p.Region__c AND Year__c =:p.Start_Year_Project__c ]; for(Project__c a : Trigger.New) { a.Goal__c = s.Id; } } }
Here's my Test Class so far.....
@isTest private class TestUpdateRelatedGoal { @isTest static void TestGoalUpdateWithStartDate() { // Create Project Manager Project_Manager__c pm = new Project_Manager__c(Name='mwp'); insert pm; // Create Account Account acct = new Account(Name='Acme'); insert acct; // Create Contact Contact cont = new Contact(FirstName='joe',LastName='blow1',email='joe@mail.com', title='president'); insert cont; // Create Proposal Proposal__c prop = new Proposal__c(Name='Test Proposal',Date__c=System.today(),Proposal_Estimate__c=1000, Contact__c=cont.Id, Service_Type__c='Other'); insert prop; // Create Project RecordType rt = [SELECT Id FROM RecordType WHERE SObjectType='Project__c' AND Name='Confirmation of Service' LIMIT 1]; Project__c prj = new Project__c(Proposal__c=prop.Id,Start_Date_Project__c=System.today(),End_Date_Project__c=System.today(),Account__c=acct.Id,Project_Contact__c=cont.Id); prj.Name = 'test'; prj.Service_Type__c='Other'; prj.Substance_Code__c='33 Workforce'; prj.Project_Manager__c=pm.Id; prj.Account__c=acct.Id; // Perform test Test.startTest(); insert prj; // This row is where error occurs Test.stopTest(); } }
Please specify some value to Start_Year_Project__c on Project__c object in test class
Please mark as best answer if the above helps ..!!!
Project__c prj = newProject__c(Proposal__c=prop.Id,Start_Date_Project__c=System.today(),End_Date_Project__c=System.tod
So please specify some value to Start_Year_Project__c on Project__c in test class.
sObject s = [SELECT Id FROM Goals__c WHERE Region_Name__c =:p.Region__c AND Year__c=:p.Start_Year_Project__c ];