-2
 public Pagereference CancelRec() {
        GS_Mass_Debrief__c headerrec = [Select id,name from GS_Mass_Debrief__c where Name =:Apexpages.currentpage().getparameters().get ('Name') limit 1];
        PageReference headerPage = new PageReference ('/'+headerrec.Id);
                   return headerPage ;

PageReference tpageRef = Page.GS_EditGroupedWorkorders;
    tpageRef.getParameters().put('id', workOrderlist[0].Id);
    Test.setCurrentPage(tpageRef);

    System.assertEquals(Apexpages.currentpage().getparameters().get ('Id'),workOrder1.id);
    Test.stopTest();

    ApexPages.StandardController controller = new ApexPages.StandardController(md);
    GS_EditGroupedWorkordersController gs = new GS_EditGroupedWorkordersController(controller);
    gs.CancelRec();

I m getting an error :

System.QueryException: List has no rows for assignment to SObject

Can someone help here?

1

In the class, you're looking for a Name, but in your test class, you're setting an Id. You'll need to change one or the other to match. Since I don't know how your class is used, it's likely you probably want to change the unit test to retrieve the work order name, and set the Name parameter.

  • I have tried passing name also,the same error repeats – swetha a Jul 13 '18 at 5:22
  • @swethaa You need to query the record back from the database, since the name is apparently auto-generated. – sfdcfox Jul 13 '18 at 5:24
0

Try this. But make sure you have added the WorkOrder and GS_Mass_Debrief__c record which is having the same name.

// You have added WorkOrder records and GS_Mass_Debrief__c records too 
//before reaching to this statement 
// GS_Mass_Debrief__c record name should match the WorkOrder record name as 
// well and I think WorkOrder name is AutoNumber field
PageReference tpageRef = Page.GS_EditGroupedWorkorders;
tpageRef.getParameters().put('id', workOrderlist[0].Id);
tpageRef.getParameters().put('Name', workOrderlist[0].Name);
Test.setCurrentPage(tpageRef);

System.assertEquals(Apexpages.currentpage().getparameters().get ('Id'), workOrder1.id);


ApexPages.StandardController controller = new ApexPages.StandardController(md);
GS_EditGroupedWorkordersController gs = new GS_EditGroupedWorkordersController(controller);
gs.CancelRec();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.