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();
}
}
}
}
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
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP