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!

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 =,
                                    of_Months__c = 12,
                                    Date_Received__c =,
                                    Date_Received_Executed__c =,
                                    Subscription_Status__c = 'Active',
                                    Dealer_Sales_Person__c = 'Mike Gray',
                                    Software_End_User_Agreement_Version_Date__c =;
        insert sub;
//create a license Record
        Subscription_Assets__c asset = new Subscription_Assets__c(
                                    Support_Subscription__c = sub.Id);
        insert asset;

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

PageReference testPage = Page.CW_Subscription_Purchase_Agreement;
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 =;
    insert addlic;

    PageReference pageRef = ApexPages.currentPage();
    return pageRef;  

public class AccountWrapper
    public Subscription_Assets__c asset{get; private set;}
    public Integer ident{get; private set;}
    public AccountWrapper(Integer 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!

Ask a Question

Get help from others!

© 2024 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP