Can't access wrapper list in test method
How certain is a caster of when their spell will end?
Does Peach's float negate shorthop knockback multipliers?
Bent spoke design wheels — feasible?
Why is c4 bad when playing the London against a King's Indian?
Secure offsite backup, even in the case of hacker root access
Pronoun introduced before its antecedent
Company is asking me to work from overseas, but wants me to take a paycut
Did Darth Vader wear the same suit for 20+ years?
1980s (or earlier) book where people live a long time but they have short memories
Word for a small burst of laughter that can't be held back
Is it a problem that pull requests are approved without any comments
How much water is needed to create a Katana capable of cutting flesh, bones and wood?
How to make thick Asian sauces?
correct term describing the action of sending a brand-new ship out into its first seafaring trip
How bad would a partial hash leak be, realistically?
Can you please explain this joke: "I'm going bananas is what I tell my bananas before I leave the house"?
How to pass a regex when finding a directory path in bash?
Why do guitarists wave their guitars?
What's the correct term for a waitress in the Middle Ages?
Did thousands of women die every year due to illegal abortions before Roe v. Wade?
What's the logic behind the the organization of Hamburg's bus transport into "rings"?
Do adult Russians normally hand-write Cyrillic as cursive or as block letters?
Movie where a boy is transported into the future by an alien spaceship
PhD student with mental health issues and bad performance
Can't access wrapper list in test method
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have a helper class that has a wrapper class in it. I use the wrapper to return two lists in a method.
Example:
public static revenueWrapper createRevenue(List<Project_Submission__c> projSubList, Map<String, Period> periodMap)
{
revenueWrapper rev = new revenueWrapper();
for(Project_Submission__c ps : projSubList)
Revenue_Pipeline__c revPipe = new Revenue_Pipeline__c();
revPipe.External_Id__c = extCom;
revPipe.NPD_Forecast_Category__c = 'Commercial Budget';
revPipe.CurrencyIsoCode = ps.CurrencyIsoCode;
revPipe.Project_Submission__c = ps.Id;
rev.revPipe.add(revPipe);
rev.revPipeSchedule.addAll(createschedule(ps.Id, launch));
public class revenueWrapper
List<Revenue_Pipeline__c> revPipe = new List<Revenue_Pipeline__c>();
List<Revenue_Pipeline_Schedule__c> revPipeSchedule = new List<Revenue_Pipeline_Schedule__c>();
Now in my test I'm sending info to the method and returning a result:
@isTest static void testcreateRevenue_B1()
List<Project_Submission__c> ps = [
SELECT Id,
CurrencyISOCode,
Year_1_Commercial_Budget__c
FROM Project_Submission__c];
ps[0].Target_Launch_Date__c = System.Date.today();
ps[0].Year_1_Commercial_Budget__c = 1000;
List<Period> periodList = NPD_ProjectSubmissionHelper.getfiscalPeriod();
Map<String, Period> periodMap = NPD_ProjectSubmissionHelper.makeMap(periodList);
Test.startTest();
NPD_ProjectSubmissionHelper.revenueWrapper results = new NPD_ProjectSubmissionHelper.revenueWrapper();
results = NPD_ProjectSubmissionHelper.createRevenue(ps, periodMap);
System.debug('results are:: ' + results);
//System.assertEquals(1, results,
//'The revenue should have been created');
Test.stopTest();
In the dev console in the debug log I can see that the the revPipe list is populated from the wrapper
|DEBUG|results are:: revenueWrapper:[revPipe=(Revenue_Pipeline__c:External_Id__c=a0Gm00000037U18EAE-CommercialBudget, NPD_Forecast_Category__c=Commercial Budget, CurrencyIsoCode=USD, Project_Submission__c=a0Gm00000037U18EAE)...
My problem is when I try to reference the list I get the error:
Variable is not visible: NPD_ProjectSubmissionHelper.revenueWrapper.revPipe
How can I get to the wrapper list to assert on? Changing the class to @testVisible does nothing
apex unit-test
add a comment |
I have a helper class that has a wrapper class in it. I use the wrapper to return two lists in a method.
Example:
public static revenueWrapper createRevenue(List<Project_Submission__c> projSubList, Map<String, Period> periodMap)
{
revenueWrapper rev = new revenueWrapper();
for(Project_Submission__c ps : projSubList)
Revenue_Pipeline__c revPipe = new Revenue_Pipeline__c();
revPipe.External_Id__c = extCom;
revPipe.NPD_Forecast_Category__c = 'Commercial Budget';
revPipe.CurrencyIsoCode = ps.CurrencyIsoCode;
revPipe.Project_Submission__c = ps.Id;
rev.revPipe.add(revPipe);
rev.revPipeSchedule.addAll(createschedule(ps.Id, launch));
public class revenueWrapper
List<Revenue_Pipeline__c> revPipe = new List<Revenue_Pipeline__c>();
List<Revenue_Pipeline_Schedule__c> revPipeSchedule = new List<Revenue_Pipeline_Schedule__c>();
Now in my test I'm sending info to the method and returning a result:
@isTest static void testcreateRevenue_B1()
List<Project_Submission__c> ps = [
SELECT Id,
CurrencyISOCode,
Year_1_Commercial_Budget__c
FROM Project_Submission__c];
ps[0].Target_Launch_Date__c = System.Date.today();
ps[0].Year_1_Commercial_Budget__c = 1000;
List<Period> periodList = NPD_ProjectSubmissionHelper.getfiscalPeriod();
Map<String, Period> periodMap = NPD_ProjectSubmissionHelper.makeMap(periodList);
Test.startTest();
NPD_ProjectSubmissionHelper.revenueWrapper results = new NPD_ProjectSubmissionHelper.revenueWrapper();
results = NPD_ProjectSubmissionHelper.createRevenue(ps, periodMap);
System.debug('results are:: ' + results);
//System.assertEquals(1, results,
//'The revenue should have been created');
Test.stopTest();
In the dev console in the debug log I can see that the the revPipe list is populated from the wrapper
|DEBUG|results are:: revenueWrapper:[revPipe=(Revenue_Pipeline__c:External_Id__c=a0Gm00000037U18EAE-CommercialBudget, NPD_Forecast_Category__c=Commercial Budget, CurrencyIsoCode=USD, Project_Submission__c=a0Gm00000037U18EAE)...
My problem is when I try to reference the list I get the error:
Variable is not visible: NPD_ProjectSubmissionHelper.revenueWrapper.revPipe
How can I get to the wrapper list to assert on? Changing the class to @testVisible does nothing
apex unit-test
add a comment |
I have a helper class that has a wrapper class in it. I use the wrapper to return two lists in a method.
Example:
public static revenueWrapper createRevenue(List<Project_Submission__c> projSubList, Map<String, Period> periodMap)
{
revenueWrapper rev = new revenueWrapper();
for(Project_Submission__c ps : projSubList)
Revenue_Pipeline__c revPipe = new Revenue_Pipeline__c();
revPipe.External_Id__c = extCom;
revPipe.NPD_Forecast_Category__c = 'Commercial Budget';
revPipe.CurrencyIsoCode = ps.CurrencyIsoCode;
revPipe.Project_Submission__c = ps.Id;
rev.revPipe.add(revPipe);
rev.revPipeSchedule.addAll(createschedule(ps.Id, launch));
public class revenueWrapper
List<Revenue_Pipeline__c> revPipe = new List<Revenue_Pipeline__c>();
List<Revenue_Pipeline_Schedule__c> revPipeSchedule = new List<Revenue_Pipeline_Schedule__c>();
Now in my test I'm sending info to the method and returning a result:
@isTest static void testcreateRevenue_B1()
List<Project_Submission__c> ps = [
SELECT Id,
CurrencyISOCode,
Year_1_Commercial_Budget__c
FROM Project_Submission__c];
ps[0].Target_Launch_Date__c = System.Date.today();
ps[0].Year_1_Commercial_Budget__c = 1000;
List<Period> periodList = NPD_ProjectSubmissionHelper.getfiscalPeriod();
Map<String, Period> periodMap = NPD_ProjectSubmissionHelper.makeMap(periodList);
Test.startTest();
NPD_ProjectSubmissionHelper.revenueWrapper results = new NPD_ProjectSubmissionHelper.revenueWrapper();
results = NPD_ProjectSubmissionHelper.createRevenue(ps, periodMap);
System.debug('results are:: ' + results);
//System.assertEquals(1, results,
//'The revenue should have been created');
Test.stopTest();
In the dev console in the debug log I can see that the the revPipe list is populated from the wrapper
|DEBUG|results are:: revenueWrapper:[revPipe=(Revenue_Pipeline__c:External_Id__c=a0Gm00000037U18EAE-CommercialBudget, NPD_Forecast_Category__c=Commercial Budget, CurrencyIsoCode=USD, Project_Submission__c=a0Gm00000037U18EAE)...
My problem is when I try to reference the list I get the error:
Variable is not visible: NPD_ProjectSubmissionHelper.revenueWrapper.revPipe
How can I get to the wrapper list to assert on? Changing the class to @testVisible does nothing
apex unit-test
I have a helper class that has a wrapper class in it. I use the wrapper to return two lists in a method.
Example:
public static revenueWrapper createRevenue(List<Project_Submission__c> projSubList, Map<String, Period> periodMap)
{
revenueWrapper rev = new revenueWrapper();
for(Project_Submission__c ps : projSubList)
Revenue_Pipeline__c revPipe = new Revenue_Pipeline__c();
revPipe.External_Id__c = extCom;
revPipe.NPD_Forecast_Category__c = 'Commercial Budget';
revPipe.CurrencyIsoCode = ps.CurrencyIsoCode;
revPipe.Project_Submission__c = ps.Id;
rev.revPipe.add(revPipe);
rev.revPipeSchedule.addAll(createschedule(ps.Id, launch));
public class revenueWrapper
List<Revenue_Pipeline__c> revPipe = new List<Revenue_Pipeline__c>();
List<Revenue_Pipeline_Schedule__c> revPipeSchedule = new List<Revenue_Pipeline_Schedule__c>();
Now in my test I'm sending info to the method and returning a result:
@isTest static void testcreateRevenue_B1()
List<Project_Submission__c> ps = [
SELECT Id,
CurrencyISOCode,
Year_1_Commercial_Budget__c
FROM Project_Submission__c];
ps[0].Target_Launch_Date__c = System.Date.today();
ps[0].Year_1_Commercial_Budget__c = 1000;
List<Period> periodList = NPD_ProjectSubmissionHelper.getfiscalPeriod();
Map<String, Period> periodMap = NPD_ProjectSubmissionHelper.makeMap(periodList);
Test.startTest();
NPD_ProjectSubmissionHelper.revenueWrapper results = new NPD_ProjectSubmissionHelper.revenueWrapper();
results = NPD_ProjectSubmissionHelper.createRevenue(ps, periodMap);
System.debug('results are:: ' + results);
//System.assertEquals(1, results,
//'The revenue should have been created');
Test.stopTest();
In the dev console in the debug log I can see that the the revPipe list is populated from the wrapper
|DEBUG|results are:: revenueWrapper:[revPipe=(Revenue_Pipeline__c:External_Id__c=a0Gm00000037U18EAE-CommercialBudget, NPD_Forecast_Category__c=Commercial Budget, CurrencyIsoCode=USD, Project_Submission__c=a0Gm00000037U18EAE)...
My problem is when I try to reference the list I get the error:
Variable is not visible: NPD_ProjectSubmissionHelper.revenueWrapper.revPipe
How can I get to the wrapper list to assert on? Changing the class to @testVisible does nothing
apex unit-test
apex unit-test
asked 9 hours ago
Dan WoodingDan Wooding
1,9951539
1,9951539
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
The wrapper class's instance variables have no access specifier, meaning that they get private
as the default:
[private] List<Revenue_Pipeline__c> revPipe = ;
[private] List<Revenue_Pipeline_Schedule__c> = ;
It's the instance variables that need the @TestVisible
annotation, rather than their enclosing class. That will make them available in test code.
Link to doc, in case you want to put that in: developer.salesforce.com/docs/atlas.en-us.apexcode.meta/…
– sfdcfox
8 hours ago
Thanks, @sfdcfox! Added inline.
– David Reed♦
8 hours ago
I read a few posts where someone wrote making @testVisible is a last resort. In theory I can make it public list<revenue pipeline>.. and get the same results?
– Dan Wooding
8 hours ago
2
@DanWooding Yeah, that'll work fine. The only reason I am aware of not to use@TestVisible
is based on (a) ideological purity about OOP encapsulation or (b) concern about making the tests fragile by inspecting the inner state of your classes that are felt to be implementation details.public
of course has a much broader effect.
– David Reed♦
8 hours ago
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "459"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f264421%2fcant-access-wrapper-list-in-test-method%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The wrapper class's instance variables have no access specifier, meaning that they get private
as the default:
[private] List<Revenue_Pipeline__c> revPipe = ;
[private] List<Revenue_Pipeline_Schedule__c> = ;
It's the instance variables that need the @TestVisible
annotation, rather than their enclosing class. That will make them available in test code.
Link to doc, in case you want to put that in: developer.salesforce.com/docs/atlas.en-us.apexcode.meta/…
– sfdcfox
8 hours ago
Thanks, @sfdcfox! Added inline.
– David Reed♦
8 hours ago
I read a few posts where someone wrote making @testVisible is a last resort. In theory I can make it public list<revenue pipeline>.. and get the same results?
– Dan Wooding
8 hours ago
2
@DanWooding Yeah, that'll work fine. The only reason I am aware of not to use@TestVisible
is based on (a) ideological purity about OOP encapsulation or (b) concern about making the tests fragile by inspecting the inner state of your classes that are felt to be implementation details.public
of course has a much broader effect.
– David Reed♦
8 hours ago
add a comment |
The wrapper class's instance variables have no access specifier, meaning that they get private
as the default:
[private] List<Revenue_Pipeline__c> revPipe = ;
[private] List<Revenue_Pipeline_Schedule__c> = ;
It's the instance variables that need the @TestVisible
annotation, rather than their enclosing class. That will make them available in test code.
Link to doc, in case you want to put that in: developer.salesforce.com/docs/atlas.en-us.apexcode.meta/…
– sfdcfox
8 hours ago
Thanks, @sfdcfox! Added inline.
– David Reed♦
8 hours ago
I read a few posts where someone wrote making @testVisible is a last resort. In theory I can make it public list<revenue pipeline>.. and get the same results?
– Dan Wooding
8 hours ago
2
@DanWooding Yeah, that'll work fine. The only reason I am aware of not to use@TestVisible
is based on (a) ideological purity about OOP encapsulation or (b) concern about making the tests fragile by inspecting the inner state of your classes that are felt to be implementation details.public
of course has a much broader effect.
– David Reed♦
8 hours ago
add a comment |
The wrapper class's instance variables have no access specifier, meaning that they get private
as the default:
[private] List<Revenue_Pipeline__c> revPipe = ;
[private] List<Revenue_Pipeline_Schedule__c> = ;
It's the instance variables that need the @TestVisible
annotation, rather than their enclosing class. That will make them available in test code.
The wrapper class's instance variables have no access specifier, meaning that they get private
as the default:
[private] List<Revenue_Pipeline__c> revPipe = ;
[private] List<Revenue_Pipeline_Schedule__c> = ;
It's the instance variables that need the @TestVisible
annotation, rather than their enclosing class. That will make them available in test code.
edited 8 hours ago
answered 9 hours ago
David Reed♦David Reed
43.5k82564
43.5k82564
Link to doc, in case you want to put that in: developer.salesforce.com/docs/atlas.en-us.apexcode.meta/…
– sfdcfox
8 hours ago
Thanks, @sfdcfox! Added inline.
– David Reed♦
8 hours ago
I read a few posts where someone wrote making @testVisible is a last resort. In theory I can make it public list<revenue pipeline>.. and get the same results?
– Dan Wooding
8 hours ago
2
@DanWooding Yeah, that'll work fine. The only reason I am aware of not to use@TestVisible
is based on (a) ideological purity about OOP encapsulation or (b) concern about making the tests fragile by inspecting the inner state of your classes that are felt to be implementation details.public
of course has a much broader effect.
– David Reed♦
8 hours ago
add a comment |
Link to doc, in case you want to put that in: developer.salesforce.com/docs/atlas.en-us.apexcode.meta/…
– sfdcfox
8 hours ago
Thanks, @sfdcfox! Added inline.
– David Reed♦
8 hours ago
I read a few posts where someone wrote making @testVisible is a last resort. In theory I can make it public list<revenue pipeline>.. and get the same results?
– Dan Wooding
8 hours ago
2
@DanWooding Yeah, that'll work fine. The only reason I am aware of not to use@TestVisible
is based on (a) ideological purity about OOP encapsulation or (b) concern about making the tests fragile by inspecting the inner state of your classes that are felt to be implementation details.public
of course has a much broader effect.
– David Reed♦
8 hours ago
Link to doc, in case you want to put that in: developer.salesforce.com/docs/atlas.en-us.apexcode.meta/…
– sfdcfox
8 hours ago
Link to doc, in case you want to put that in: developer.salesforce.com/docs/atlas.en-us.apexcode.meta/…
– sfdcfox
8 hours ago
Thanks, @sfdcfox! Added inline.
– David Reed♦
8 hours ago
Thanks, @sfdcfox! Added inline.
– David Reed♦
8 hours ago
I read a few posts where someone wrote making @testVisible is a last resort. In theory I can make it public list<revenue pipeline>.. and get the same results?
– Dan Wooding
8 hours ago
I read a few posts where someone wrote making @testVisible is a last resort. In theory I can make it public list<revenue pipeline>.. and get the same results?
– Dan Wooding
8 hours ago
2
2
@DanWooding Yeah, that'll work fine. The only reason I am aware of not to use
@TestVisible
is based on (a) ideological purity about OOP encapsulation or (b) concern about making the tests fragile by inspecting the inner state of your classes that are felt to be implementation details. public
of course has a much broader effect.– David Reed♦
8 hours ago
@DanWooding Yeah, that'll work fine. The only reason I am aware of not to use
@TestVisible
is based on (a) ideological purity about OOP encapsulation or (b) concern about making the tests fragile by inspecting the inner state of your classes that are felt to be implementation details. public
of course has a much broader effect.– David Reed♦
8 hours ago
add a comment |
Thanks for contributing an answer to Salesforce Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f264421%2fcant-access-wrapper-list-in-test-method%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown