function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AmphitriteAmphitrite 

Test Get Options Method - by Profile

Can anyone assist with the test code for the following controller extension method? It returns a default set of options and then additional options based on profile. Any assistance would be appreciated.

 

 

 //getOptions Method
        public List<SelectOption> getOptions(){
               
        List<SelectOption> options = new List<SelectOption>();
        
        options.add(new SelectOption('','--select--'));
        options.add(new SelectOption('Next','Next RC'));
        options.add(new SelectOption('Previous','Previous RC'));
        options.add(new SelectOption('getProperty','Assign Property Contact'));
        options.add(new SelectOption('getCorporate','Assign Corporate Contact'));
        
               
        IF(InEditProfileTest =='000e50000000pnH3' || InEditProfileTest =='00e50000000pnCc' ){
        options.add(new SelectOption('Close','Close AM Case'));
        
        }
        
        Else IF(InEditProfileTest =='00e50000000pnCmAAI'){
        options.add(new SelectOption('ExceptionON','Owner Exception ON'));
        options.add(new SelectOption('ExceptionOFF','Owner Exception OFF'));
        options.add(new SelectOption('Refresh','Refresh Case'));
        
        }
                
        Else If(InEditProfileTest=='00e30000000gvVd' || InEditProfileTest =='00e50000000pl2e'){
        
        options.add(new SelectOption('ExceptionON','Owner Exception ON'));
        options.add(new SelectOption('ExceptionOFF','Owner Exception OFF'));
        options.add(new SelectOption('Refresh','Refresh Case'));
        options.add(new SelectOption('Complete','Auto Complete'));
        options.add(new SelectOption('Cancel','Cancel'));
        options.add(new SelectOption('Clear Cancel','Clear Cancel'));
        options.add(new SelectOption('ResetAll','Reset'));
        options.add(new SelectOption('Terminate','Terminate'));
        options.add(new SelectOption('Delete','Delete'));
               
               
        }
        
  
         return options;
        }      

 

 

 

 

Saikishore Reddy AengareddySaikishore Reddy Aengareddy

In your test method... 

1. use seealldata = true

2. query the profiles that you wanted to test (all the profiles in the if conditions)

3. create users with different profiles from step 2

4. use system.runas to test with different users 

 

this way you can cover the complete code coverage..

 

follow this link for more info..

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_testing_example.htm#second_user

vbsvbs
@Sam - Agree with all the steps except for annotation seealldata = true. This is not a good practice as it means the test case is reliant on existing data in the instance. Please make sure to setup all data in the test class or relevant method or use Test.loaddata to setup test data from Static Resource. Also cover different assertions for different profiles/users.
Saikishore Reddy AengareddySaikishore Reddy Aengareddy
@vbs: Agreed! The only reson is the ID's of the profile are hard coded in the controller!!!