+ Start a Discussion
Scott LandesScott Landes 

Test Class "variable does not exist" compiling error

Hey All,

I'm a bit new to writing apex and test classes, but I'm unsure why I'm getting the compiling error "Variable does not exist: Monthly_Recurring_Fees__c". I'm attempting to pull the "Monthly_Recurring_Fees__c" field from the "queriedOrder" query. Any help is appreciated!

@isTest
private class OrderRollupSummaryTest {

    private static testMethod void doTest() {
    	
    	Account testAcc  = new Account ();          
    			testAcc.Name = 'Test Account';
    			testAcc.Primary_Vertical__c = 'Multifamily Housing';
    			testAcc.Total_Locations_Owned_Managed__c = 1;
    			
    			insert testAcc;


    	Opportunity testOpp  = new Opportunity ();
       			testOpp.Name = 'Test Opportunity';
    			testOpp.AccountId = testAcc.Id;
    			testOpp.Opportunity_Source__c = 'Sales Generated';
    			testOpp.Type = 'New';
    			testOpp.StageName = 'Contract';
    			testOpp.Number_of_locations_for_opportunity__c = 1;
    			testOpp.Amount = 0;
    			testOpp.Implementation__c = 0;
    			testOpp.CloseDate = System.today() + 5;
    			testOpp.Deal_Confidence__c = 100;
    			
    			insert testOpp;

    	Package__c testPackage  = new Package__c ();
    			testPackage.Name = 'Test Package';
    			testPackage.Package_Type__c = 'Website Package';
    			testPackage.Status__c = 'Active';
    			testPackage.One_Time_Price__c = String.ValueOf(200);
    			testPackage.Monthly_Recurring_Price__c = String.ValueOf(100);
    			
    			insert testPackage;


    	Order_Sheet__c testOrder  = new Order_Sheet__c ();
    			testOrder.Opportunity__c = testOpp.id;
    			
    			insert testOrder;


    	Order_New_Location__c testOrderLocation  = new Order_New_Location__c ();
    			testOrderLocation.Order_Sheet__c = testOrder.id;
    			testOrderLocation.Name = 'Test Location';
    			
    			insert testOrderLocation;


    	Order_Location_Package__c testOrderPackage  = new Order_Location_Package__c ();
    			testOrderPackage.Order__c = testOrder.Id;
    			testOrderPackage.New_Location_Name__c = testOrderLocation.Id;
    			testOrderPackage.Package__c = testPackage.Id;
    			
    			insert testOrderPackage;

        Discount__c testMRFDiscount  = new Discount__c ();
                testMRFDiscount.Location_Package__c = testOrderPackage.Id;
                testMRFDiscount.Dollar_Discount__c = 50;
                testMRFDiscount.Fee__c = 'Monthly Recurring Fees';
                
                insert testMRFDiscount;

        Discount__c testOTFDiscount  = new Discount__c ();
                testOTFDiscount.Location_Package__c = testOrderPackage.Id;
                testOTFDiscount.Dollar_Discount__c = 50;
                testOTFDiscount.Fee__c = 'One-Time Fees';
                
                insert testOTFDiscount;


 /* --- OrderRollupSummaryTest Test --- */
		Test.startTest();

		/* --- Run Create Method--- */
    	OrderRollupSummary.rollupAllorderlocations(new List<Order_New_Location__c>{testOrderLocation});
		
		/* --- Query for Order--- */
		list<Order_Sheet__c>queriedOrder = [Select Monthly_Recurring_Fees__c FROM Order_Sheet__c WHERE Id = :testOrder.id];
        System.debug('Price after trigger fired: ' + queriedOrder.Monthly_Recurring_Fees__c);
		
		/* --- Checks to see if amounts updated --- */
        system.assertEquals(50, queriedOrder.Monthly_Recurring_Fees__c);

        Test.stopTest();


    }
}
Best Answer chosen by Scott Landes
Andrew GAndrew G
the query extracts a list
list<Order_Sheet__c>queriedOrder = [SELECT .....
this statement treats it as a single record:
System.debug('Price after trigger fired: ' + queriedOrder.Monthly_Recurring_Fees__c);

Since we are dealing with a list, a few options - 
debugs the first entry returned:
System.debug('Price after trigger fired: ' + queriedOrder[0].Monthly_Recurring_Fees__c);
loop using integer:
For (integer i =0; i<queriedOrder.size();i++){
 System.debug('Price after trigger fired: ' + queriedOrder[i].Monthly_Recurring_Fees__c);
}
Loop using object
For(Order_Sheet__c os : queriedOrder) {
    System.debug('Price after trigger fired: ' + os.Monthly_Recurring_Fees__c); 
}

HTH


regards
Andrew



 

All Answers

Andrew GAndrew G
the query extracts a list
list<Order_Sheet__c>queriedOrder = [SELECT .....
this statement treats it as a single record:
System.debug('Price after trigger fired: ' + queriedOrder.Monthly_Recurring_Fees__c);

Since we are dealing with a list, a few options - 
debugs the first entry returned:
System.debug('Price after trigger fired: ' + queriedOrder[0].Monthly_Recurring_Fees__c);
loop using integer:
For (integer i =0; i<queriedOrder.size();i++){
 System.debug('Price after trigger fired: ' + queriedOrder[i].Monthly_Recurring_Fees__c);
}
Loop using object
For(Order_Sheet__c os : queriedOrder) {
    System.debug('Price after trigger fired: ' + os.Monthly_Recurring_Fees__c); 
}

HTH


regards
Andrew



 
This was selected as the best answer
Andrew GAndrew G
As an aside, i would move your Test.stopTest(); to before the query of the results.

regards
Andrew
Scott LandesScott Landes
Thanks so much, Andrew! I knew it was something simple I was missing. Appreciate it!