0

Can someone help me to understand why I am getting below error message? It is referring to the lines with DocumentQUoteEmailController and List<contact>.

It seems that I already entered these objects so it shouldn't be null

System.QueryException: List has no rows for assignment to SObject
Class.DocumentQuoteEmailController.: line 19, column 1
Class.DocumentQuoteEmailControllerTestfromApp.test_sendDoc_UseCase1: line 28, column

Class Code:

@isTest 
private class DocumentQuoteEmailControllerTestfromApp{
    @testSetup
    static void setupTestData(){
        test.startTest();
        Quote quote_Obj = new Quote(Name = 'Name841', OpportunityId='0060n000002f0x7', Estimated_Close_date__c=Date.today());
        Insert quote_Obj; 
        Contact contact_Obj = new Contact(LastName = 'LastName924', Email = '[email protected]', MailingStreet='123 Oak St', MailingCity='Wesfield', MailingState='IN', MailingPostalCode='41311', MailingCountry='USA');
        Insert contact_Obj; 
        OrgWideEmailAddress orgwideemailaddress_Obj = new OrgWideEmailAddress(Address = '[email protected]');
        // Insert orgwideemailaddress_Obj; 
        Attachment attachment_Obj = new Attachment(ParentId = quote_Obj.id, Name = 'Name569', Body=blob.valueof('abc'));
        Insert attachment_Obj; 
        test.stopTest();
    }

    static testMethod void test_sendDoc_UseCase1(){
        List<Quote> quote_Obj  =  [SELECT Id,Assay_from_Op__c,Owner_Email__c,Sponsor_s_of_Won_Proposals__c,Sponsor_Email__c,Is_Proposal_a_Change_Order__c from Quote];
        System.assertEquals(true,quote_Obj.size()>0);
        List<Contact> contact_Obj  =  [SELECT Id, Email from Contact];
        System.assertEquals(true,contact_Obj.size()>0);
        List<OrgWideEmailAddress> orgwideemailaddress_Obj  =  [SELECT Id from OrgWideEmailAddress];
        System.assertEquals(true,orgwideemailaddress_Obj.size()>0);
        List<Attachment> attachment_Obj  =  [SELECT ParentId,Name,BodyLength,Body,CreatedDate from Attachment];
        System.assertEquals(true,attachment_Obj.size()>0);
        PageReference pageRef = Page.EmailQuotewithAttachment;
        pageRef.getParameters().put('Id','test');
        Test.setCurrentPage(pageRef);
        DocumentQuoteEmailController obj01 = new DocumentQuoteEmailController(new ApexPages.StandardController(quote_Obj[0]));
        obj01.email = 'test data';
        obj01.attachment = new Attachment();
        obj01.quoteId = 'test data';
        obj01.qte = new Quote();
        obj01.abc = new Quote();
        obj01.q = 'test data';
        obj01.sendDoc();
    }
}
1
  • 2
    We need to see the controller class in order to help you.
    – Adrian Larson
    Sep 15, 2017 at 16:38

1 Answer 1

0

You are passing the parameters incorrectly. Following this line incorrect. You need to pass correct Id value as parameter.

 pageRef.getParameters().put('Id','test');

Here is the approach:

 List<Quote> quote_Obj  =  [SELECT Id,Assay_from_Op__c,Owner_Email__c,Sponsor_s_of_Won_Proposals__c,Sponsor_Email__c,Is_Proposal_a_Change_Order__c from Quote];
System.assertEquals(true,quote_Obj.size()>0);
PageReference pageRef = Page.EmailQuotewithAttachment;

    Test.setCurrentPage(pageRef);
    //pass parameter to the page
    ApexPages.currentPage().getParameters().put('id',quote_Obj[0].Id);

    //create an instance of controller.
    ApexPages.StandardController standrdcontroller = new ApexPages.StandardController(quote_Obj[0]);

    DocumentQuoteEmailController obj01 = new DocumentQuoteEmailController(standrdcontroller);
1
  • 1
    The Id parameter is often completely irrelevant when using a standard controller. It depends how the extension is written.
    – Adrian Larson
    Sep 15, 2017 at 16:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .