You need to sign in to do that
Don't have an account?

Invalid type: OpportunitiesController test class error?
I am trying to write a test class for a simple Controller.. I think I am along the right lines but have an error: Invalid type: OpportunitiesController.. please help!
Custom Controller
Test Class method
Custom Controller
public class OpportunityController { public List<Opportunity> opp {get;set;} public OpportunityController() { opp = [SELECT Id, Name, CreatedDate, StageName, Placement__c, LDN_Company__c, Description, Job_Title__c, CloseDate, NextStep, Salary__c, Future_Prospects__c, Duration__c, Training_Delivery_Site__c, Qualification_taken__c, Entry_Requirements__c, Key_Responsibilities__c, Skills_Required__c, Account.Name, Account.BillingPostalCode, Account.BillingStreet, Account.BillingCity FROM Opportunity WHERE (StageName = '1 - Qualifying' or StageName = '2 - Booked for CK' or StageName = '3 - Live' or StageName = '4 - Work Trial') AND (Placement__c = 'New Apprentice')]; } }
Test Class method
static testMethod void myUnitTest2() { test.startTest(); Opportunity opp = new Opportunity(); opp.Name = ' test 001'; insert opp; PageReference testPage = new pagereference('/apex/Opportunities'); ApexPages.currentPage().getParameters().put( 'id', opp.id ); OpportunitiesController OpportunitiesControllerObj = new OpportunitiesController(); PageReference pageref = OpportunitiesControllerObj.save(); OpportunitiesControllerObj.getOpportunity(); test.stopTest(); }
Your class name is OpportunityController and you are writing "OpportunitiesController" . Change it to "OpportunityController".
Hope it helps, if it does, mark it as solved.
Thanks
Haa - very silly of me.
I am now receiving 2 more errors, would you happen to know what these are about?
Method does not exist or incorrect signature: void save() from the type OpportunityController
Method does not exist or incorrect signature: void getOpportunity() from the type OpportunityController
Thank you!
These two methods does not exist in OpportunityController and you are doing the query in constructor.
Thanks
Greetings to you!
- I read your problem and implemented in my Org.
- Please use the below test class [Solved] : -
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha.
Instance variable names should be lower case.
Asserts should be added. It is not really a test class unless it is testing something.
testMethod it deprecated.
Unless you plan on calling the test class or test methods of this class from another test class then the test class should be made to be private.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_isTest.htm