• Kory Howard
  • NEWBIE
  • 0 Points
  • Member since 2014
  • Salesforce.com Administrator
  • Advicent Solutions

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi all,

I have created a custom visualforce page for forecasting at my company. The page calls a custom controller, which queries the RevenueForecast object for the running user's Quota information.
List<RevenueForecast> quotaList = [select Quota, ProductFamily from RevenueForecast where StartDate =: dateSelected and OwnerId =: userSelected];
This works fine when I log in as a user and open up the visualforce page - the quota values are returned for a selected month as expected.

I also created a test class to test the controller. When I run the test class I receive the following error:

"System.QueryException: sObject type 'RevenueForecast' is not supported."

In the test class I use the SetAllData=true setting and create the user within the code:
@isTest (seeAllData=true)
public class TestForecastView {
	
	@isTest public static void test_method_one() {
		// Tests the view from an end user perspective.
		PageReference pageRef = Page.ForecastView;
        Test.setCurrentPage(pageRef);
        
        //Add test data.
        Profile p = [select id from profile where name='Finance - Sales User'];
        
        User user1 = new User(
            Lastname = 'SuperMan1',
            Alias = 'sprmn1',
            Email = 'super.man1@zywave.com',
            ProfileId = p.Id,
            Username = 'super.man1@zywave.com',
            Who__c = 'BD Rep',
            emailencodingkey='UTF-8',
            languagelocalekey='en_US',
            localesidkey='en_US',
            timezonesidkey='America/Los_Angeles'
        );
        insert user1;
Then towards the end of the test class I call the controller as the new user created above:
//Test the ForecastView Apex page and ForecastViewController Apex controller.
        //================================================================================
        Test.startTest();
        System.runAs(user1){
            ForecastViewController controller = new ForecastViewController();
            controller.Refresh();
            controller.Submit();
            
            ForecastViewController controller1 = new ForecastViewController();
            controller1.Refresh();
            controller1.Submit();
        }
        Test.stopTest();
I don't see any reason why the test is returning an error message. Any assistance you can provide would be much appreciated!

-Kory
Hi all,

I have created a custom visualforce page for forecasting at my company. The page calls a custom controller, which queries the RevenueForecast object for the running user's Quota information.
List<RevenueForecast> quotaList = [select Quota, ProductFamily from RevenueForecast where StartDate =: dateSelected and OwnerId =: userSelected];
This works fine when I log in as a user and open up the visualforce page - the quota values are returned for a selected month as expected.

I also created a test class to test the controller. When I run the test class I receive the following error:

"System.QueryException: sObject type 'RevenueForecast' is not supported."

In the test class I use the SetAllData=true setting and create the user within the code:
@isTest (seeAllData=true)
public class TestForecastView {
	
	@isTest public static void test_method_one() {
		// Tests the view from an end user perspective.
		PageReference pageRef = Page.ForecastView;
        Test.setCurrentPage(pageRef);
        
        //Add test data.
        Profile p = [select id from profile where name='Finance - Sales User'];
        
        User user1 = new User(
            Lastname = 'SuperMan1',
            Alias = 'sprmn1',
            Email = 'super.man1@zywave.com',
            ProfileId = p.Id,
            Username = 'super.man1@zywave.com',
            Who__c = 'BD Rep',
            emailencodingkey='UTF-8',
            languagelocalekey='en_US',
            localesidkey='en_US',
            timezonesidkey='America/Los_Angeles'
        );
        insert user1;
Then towards the end of the test class I call the controller as the new user created above:
//Test the ForecastView Apex page and ForecastViewController Apex controller.
        //================================================================================
        Test.startTest();
        System.runAs(user1){
            ForecastViewController controller = new ForecastViewController();
            controller.Refresh();
            controller.Submit();
            
            ForecastViewController controller1 = new ForecastViewController();
            controller1.Refresh();
            controller1.Submit();
        }
        Test.stopTest();
I don't see any reason why the test is returning an error message. Any assistance you can provide would be much appreciated!

-Kory