You need to sign in to do that
Don't have an account?
Testing Visualforce controller and Page where page is readOnly
Greetings,
I have a page where the readonly attribute is set to true. This is done to overcome the limit of 50,000 records in an aggregate query..
How do I perform a unit test using this attribute? I have tried setting the application mode to read only to no avail. The test method still fails for > 50K query rows. The page works fine when viewing but I cannot get the test method to pass.
What am I missing.
Here is the unit test:
@isTest private class TestRRPage { static testMethod void myUnitTest() { PageReference pageRef2 = new PageReference('/apex/RRSpage'); Test.setCurrentPage(pageRef2); test.setReadOnlyApplicationMode(true); RRStatusController r = new RRStatusController(); test.startTest(); r.AssignRefferals(); test.stopTest(); r.ISERROR = False; r.ErrorMsg ='No Message'; system.debug('\n\n RRS = '+r.RRS); } }
Also,
The docs state that controller methods can be annotated as @readonly but the error occurs that it must be scheduleable or a webservice method. How do you mark a controller method as readOnly? Do I have to make it a webservice method?
Use Test.isRunningTest in your class and put a limit in query there .
example
Use this in your apex class and this will help to avoid the heavy query during test run.Great luck!!
Agreed, this is what I have done..
The problem is that it basically nullifies the test method. I am not really testing results that will happen when the user loads the page, rather I am artificially creating a scenerio that the test will pass. I hate writing code just for the sake of writing code...
Sets the application mode for an organization to read-only in an Apex test to simulate read-only mode during Salesforce upgrades and downtimes. The application mode is reset to the default mode at the end of each Apex test run.
setReadOnlyApplicationMode is available as part of 5 Minute Upgrade.
So using setReadOnlyApplicationMode will not help us for sure .
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_annotation_ReadOnly.htm
Here is the salesforce document for @Readonly annotation and hence you will have to have an schedulable inteface or make the top level Controller class to be called from webservice.
I would avoid doing complex stuff for just passing the test class.
I read that as well but was hopeing that it would still work.
Seems there is no way to simulate the VF Page @readOnly mode.
Yes that is true.
But that is not what I am doing here.
The visualforce page is set to readOnly="true" which accomplishes the same thing. There are over 50K records and it works fine.
But the test method fails because there are over 50K records (old api and sees all data);
So the test methods has to be manipulated to pass and thus there is no reason to write the test method other than to execute lines.......(part I hate)
It would be more appropriate to allow the settings of the pagereference the test method is set to, to control the parameters of the transaction during the test...