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
SFDC n12SFDC n12 

Test class help needed

Hi,

can you tell me how to cover the following methods in my test class,

private void getusers()
    {
     usr = AF_DealerCRM_Utility.getUserInfo();
    }


***************************************************************************

public AF_AccountExtension()
    {
       exRepList = [Select Name,URL__c,Report_Link__c,Short_Description__c,Primary_Contact__c,Storage_Location__c,FileNameFilter__c from External_Reports__c Where isActive__c = true AND FileNameFilter__c != 'PDN'];
    
       if(usr == null)
       {
          getusers();
       }
       system.debug('userprofilename'+usr.profile.name);
    
       if((usr.profile.name !='AF: RVP' ) && (usr.profile.name !='AF: Account Executive') && ( usr.profile.name !='AF: Director of Sales'))
       {
          exRepList = null;
          repLink = null;         
          Apexpages.addMessage(new apexpages.message(Apexpages.Severity.ERROR,System.Label.AF_Home_Page_Reports));
       }

Thanks in Advance
Sonam_SFDCSonam_SFDC
Looks like public AF_AccountExtension() is a constructor..as this loads as soon as you instantiate the object - it will be invoked.
Please create an object of this class in the test class and that should do it read more: https://developer.salesforce.com/forums?id=906F00000008zbRIAQ
SFDC n12SFDC n12
thanks for it , 

usr = AF_DealerCRM_Utility.getUserInfo();

how to call the abve method in my test class  , the getuserinfo() methd is from another class and i am using it in my controller
Nickname_BravoNickname_Bravo
I dont know the class name so Im going to make my own up and you can fill in what you have. For reference go to http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_testing_tools_runas.htm. That can be used to test your code, I will display what the site says in your scenario, but I can't do the test for you because I dont have all the information on this class.

public class MyController{

..Your code above here..

}

-------- NEW CLASS ---------------

@IsTest
public class MyControllerTest{

 public static TestMethod void TheControllerTest(){
      // Setup test data
      // This code runs as the system user
     Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];
      User u = new User(Alias = 'standt', Email='standarduser@testorg.com',
      EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
      LocaleSidKey='en_US', ProfileId = p.Id,
      TimeZoneSidKey='America/Los_Angeles', UserName='standarduser@testorg.com');
System.runAs(u) {
         // The following code runs as user 'u'
         System.debug('Current User: ' + UserInfo.getUserName());
         System.debug('Current Profile: ' + UserInfo.getProfileId());

        //You can test your methods in this part
       
        

      }
}

}

Good luck. Hope that helps.
Abhi_TripathiAbhi_Tripathi
Hi Bharat,

take a look at this post
http://abhithetechknight.blogspot.in/2013/10/salesforce-test-class-basics.html

Regards,
Abhi Tripathi
Salesforce Ceritified Developer