You need to sign in to do that
Don't have an account?
Jerry Clifft
Ok, here is some wierd stuff
So, I have this apex class and test class, works fine in prod. I created a new sandbox. I wanted to change one thing in the class, it didn't work. I reverted back to the original code...now the original does not work.
Here is my class.
public class Smartbox_Equipment_CSV_FileUploader
{
ApexPages.StandardController stdCtrl; public Smartbox_Equipment_CSV_FileUploader(ApexPages.StandardController std) {stdCtrl=std;} public PageReference quicksave() {update accstoupload ;return null;} public PageReference fileAccess() {return null;}
public Smartbox_Equipment_CSV_FileUploader(){
}
public string nameFile{get;set;}
public Blob contentFile{get;set;}
String[] filelines = new String[]{};
List<Smartbox__c> accstoupload;
public Pagereference ReadFile()
{
nameFile=contentFile.toString();
filelines = nameFile.split('\n');
accstoupload = new List<Smartbox__c>();
for (Integer i=1;i<filelines.size();i++)
{
String[] inputvalues = new String[]{};
inputvalues = filelines[i].split(',');
Smartbox__c a = new Smartbox__c();
a.Chassis_Serial__c = inputvalues[0];
a.Serial_Number__c = inputvalues[2];
a.CAID__c = inputvalues[3];
a.SmartCard__c = inputvalues[4];
a.Opportunity__c = ApexPages.currentPage().getParameters().get('oppId');
accstoupload.add(a);
}
try{
insert accstoupload;
}
catch (Exception e)
{
ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured. Please check the template');
ApexPages.addMessage(errormsg);
}
return null ;} public List<Smartbox__c> getuploadedEquipment() { if (accstoupload!= NULL) if (accstoupload.size() > 0) return accstoupload; else return null; else return null;
and here is my test class.
@IsTest(SeeAllData=true)
public class Smartbox_Equipment_CSV_FileUploader_Test
{ /* public pageReference fileAccess(){
Document lstDoc = [select id,name,Body from Document where name = 'test'];
System.Debug('DOC NAME :: '+lstDoc.name);
System.Debug('DOCBODY :: '+lstDoc.Body);
return null;
} */
public static testMethod void ReadFile() {
Document lstDoc = [select id,name,Body from Document where name = 'eqtest'];
// System.Debug('DOC NAME :: '+lstDoc.name);
//System.Debug('DOCBODY :: '+lstDoc.Body);
Smartbox_Equipment_CSV_FileUploader file=new Smartbox_Equipment_CSV_FileUploader ();
file.fileAccess();
Blob content= lstDoc.Body;
file.contentFile = content; //this line doesn't exist yet
file.ReadFile(); //this line doesn't exist yet
file.nameFile=content.toString();
String[] filelines = new String[]{};
List<Smartbox__c> accstoupload;
accstoupload = new List<Smartbox__c>();
for (Integer i=1;i<filelines.size();i++)
{
String[] inputvalues = new String[]{};
inputvalues = filelines[i].split(',');
Smartbox__c a = new Smartbox__c();
a.Chassis_Serial__c = '12250000';
a.CAID__c = '10251973';
a.Serial_Number__c = '07112006';
a.SmartCard__c = '07252010';
a.Status__c = 'Activation Requested';
accstoupload.add(a);
try{
insert accstoupload;
}
catch (Exception e)
{
ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured. Please check the template');
ApexPages.addMessage(errormsg);
}
}
}
}
Here is the error I get.
Class Smartbox_Equipment_CSV_FileUploader_Test Method Name ReadFile Pass/Fail Fail Error Message System.QueryException: List has no rows for assignment to SObject Stack Trace
Class.Smartbox_Equipment_CSV_FileUploader_Test.ReadFile: line 14, column 1
I could be wrong, but you may need to add a new document with the name 'eqtest' to the new Sandbox. You may have done this, but this is line 14 in your test class, and your description doesn't mention that it has been done.
All Answers
In my SF PROD, it works just fine.
I made a brand new sandbox, code gives the error listed above.....
I could be wrong, but you may need to add a new document with the name 'eqtest' to the new Sandbox. You may have done this, but this is line 14 in your test class, and your description doesn't mention that it has been done.
You are correct, thanks for the help. Not sure how I overlooked that. Thanks again!