AnswerBun.com

List has no rows for assignment to SObject test class

Salesforce Asked by staci on January 2, 2022

Getting this error on line controller.Save();

I haven’t written a test class in a long time and I’m a bit rusty. Any help would be greatly appreciated!

@isTest 
private class MultiAdTest{
static testMethod void MultiAdTest_test() {

       Account testAccount = new Account(
        Name = 'Test Account'
    );
    
    insert testAccount;
    List<Support_Subscription__c> newsub = new List<Support_Subscription__c>();
Support_Subscription__c sub = new Support_Subscription__c(
                                    Dealer_Name__c = testAccount.Id,
                                    Subscription_Start_Date__c = Date.today(),
                                    of_Months__c = 12,
                                    Date_Received__c = Date.today(),
                                    Date_Received_Executed__c = Date.today(),
                                    Subscription_Status__c = 'Active',
                                    Dealer_Sales_Person__c = 'Mike Gray',
                                    Software_End_User_Agreement_Version_Date__c = Date.today());
       Test.startTest();
        insert sub;
        newsub.add(sub);
        
//create a license Record
        Subscription_Assets__c asset = new Subscription_Assets__c(
                                    Support_Subscription__c = sub.Id);
        insert asset;
       
          Test.stopTest(); 

ApexPages.StandardController con2 = new ApexPages.StandardController(asset);
MultiAd controller = new MultiAd(con2);
controller.Save();

PageReference testPage = Page.CW_Subscription_Purchase_Agreement;
Test.setCurrentPage(testPage);
/*
Class/Method Name: MultiAd
Description: Created Subscription Assets related to Support Subscription
Author/Date: Staci Gilmore 5/27/2020
*/
public with sharing class MultiAd { 
private final Subscription_Assets__c ln; 
Public string ss;
public List<AccountWrapper> wrappers{get;set;}
private Integer nextIdent=0;

public MultiAd(ApexPages.StandardController controller) { 

ss = ApexPages.CurrentPage().getparameters().get('id');

wrappers=new List<AccountWrapper>();
for(Integer idx=0; idx<1; idx++)
{
    wrappers.add(new AccountWrapper(nextIdent++));
}} 

public List<Subscription_Assets__c> addlic {get; set;} 
public PageReference Save()
{
    List<Subscription_Assets__c> addlic=new List<Subscription_Assets__c>();
    Support_Subscription__c ssid = [select id, Name, RecordTypeID from Support_Subscription__c where id=:ss];
    for(AccountWrapper wrap:wrappers)
    {
       Subscription_Assets__c lic =wrap.asset;
       lic.Support_Subscription__c = ssid.id;
       addlic.add(lic);
    }
        
    insert addlic;

    PageReference pageRef = ApexPages.currentPage();
    pageRef.setRedirect(true);
    return pageRef;  
}

public class AccountWrapper
{
    public Subscription_Assets__c asset{get; private set;}
    public Integer ident{get; private set;}
        
    public AccountWrapper(Integer inIdent)
    {
        ident=inIdent;
        asset=new Subscription_Assets__c();
            
    }
}         
}

}

One Answer

MultiAd sources its ss instance variable, which defines the query filter for

[select id, Name, RecordTypeID from Support_Subscription__c where id=:ss];

from the current page parameters, but your unit test class does not set the id parameter, i.e., ApexPages.currentPage().getParameters().put('id', <desired id>);

Alternately, you could simply have your extension controller get its record id directly from the standard controller via getRecord().

Answered by David Reed on January 2, 2022

Add your own answers!

Related Questions

How to truncate a string to a specific length if it is longer?

4  Asked on February 10, 2021 by imajmdf

   

Update contact activity in Journey builder

1  Asked on February 10, 2021 by mary-jon

 

Hide iframe url

1  Asked on February 8, 2021 by cloudy-ritz

       

How can we add placeholder for lightning:InputField?

1  Asked on February 6, 2021 by aakash-poudel

 

LWC OSS Build Command

1  Asked on February 3, 2021 by scott-morrison

 

%%_PreHeader%% Personalization String

1  Asked on February 2, 2021 by victorcorey

   

Marketing cloud new Transactional Messaging API

1  Asked on January 30, 2021 by martijn-e

     

Can’t send to a list in marketing cloud?

1  Asked on January 30, 2021 by 4kaudio

     

Ask a Question

Get help from others!

© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir