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

Help with Test Class not passing (List Has No Rows For Assignment)
I am in need of some great support form one of you Awesome Salesforce Guru's!
I have a Apex Controller that I am using as an extension on a VF page to handle incoming attachments and populate a look up field when the record is created from the VF page.
I can not get the test class to not fail for the following reason System.QueryException: List has no rows for assignment to SObject and the stack trace is - Class.backlogAttachment.getReleaseMethod1: line 20, column 1
Class.backlogAttachment.<init>: line 12, column 1
Class.backlogAttachmentTest.backlogAttachmentTestMethod: line 10, column 1
Here is my controller class and Test class...can you please help me figure out why thsi is failing and what to do to fix it? You woudl be a hge saviour here as I am new to apex but am trying my hardest! Thanks in advance...
Shawn
Controller Extension:
Test Class that is failing:
I have a Apex Controller that I am using as an extension on a VF page to handle incoming attachments and populate a look up field when the record is created from the VF page.
I can not get the test class to not fail for the following reason System.QueryException: List has no rows for assignment to SObject and the stack trace is - Class.backlogAttachment.getReleaseMethod1: line 20, column 1
Class.backlogAttachment.<init>: line 12, column 1
Class.backlogAttachmentTest.backlogAttachmentTestMethod: line 10, column 1
Here is my controller class and Test class...can you please help me figure out why thsi is failing and what to do to fix it? You woudl be a hge saviour here as I am new to apex but am trying my hardest! Thanks in advance...
Shawn
Controller Extension:
public with sharing class backlogAttachment { public blob getfile{get;set;} public attachment objAttachment{get;set;} public Backlog__c objcase{get;set;} public string filename{get;set;} public backlogAttachment(apexpages.standardcontroller controller) { objcase = new Backlog__c(); objAttachment = new Attachment(); Scheduled_Releases__c sr = getReleaseMethod1(); objcase.Scheduled_Release__c = sr.Id; } Scheduled_Releases__c s; public Scheduled_Releases__c getReleaseMethod1(){ if(s == null) s=[SELECT Id, Name FROM Scheduled_Releases__c WHERE Name ='Software Enhancement Request (Default)' LIMIT 1]; return s; } Public PageReference saveBacklog() { try{ insert objcase; } catch(DMLException e) { ApexPages.addMessages(e); } if(filename != null && fileName.trim().length()>0 && getfile != null) { //objAttachment = new Attachment(); Integer i=0; objAttachment.clear(); objAttachment.body = getfile; objAttachment.ParentId = objcase.Id; objAttachment.name = this.filename; try{ insert objAttachment; }catch(Exception e){ system.debug(e); } } pagereference pr = new pagereference('/'+objcase.id); return pr; } }
Test Class that is failing:
@isTest public class backlogAttachmentTest { static testMethod void backlogAttachmentTestMethod() { List<Scheduled_Releases__c> re = [SELECT Id FROM Scheduled_Releases__c WHERE Id = 'a3l4B000000CiGw' LIMIT 1]; Backlog__c temprec = new Backlog__c(); ApexPages.StandardController cs = new ApexPages.StandardController(temprec); backlogAttachment controller = new backlogAttachment(cs); controller.getfile = Blob.valueof('Test Data'); controller.filename = 'TestFieName'; controller.objcase.Scheduled_Release__c = re[0].Id; test.startTest(); controller.saveBacklog(); test.StopTest(); } }
Try like this, Let us know if it helps you.
All Answers
Try like this, Let us know if it helps you.