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
Navya sree 4Navya sree 4 

Forecast test class Help?

Hi 

Test Class Help


public with sharing class ForecastArchiveController {
    public String userInfo {get; private set;}
    public ForecastArchiveController() {
        setUserDetails(this);
    }
    
    public static void setUserDetails(ForecastArchiveController controller) {
        User userDetail = [SELECT Id, Name, Forecast_OA_Region_Name__c, Forecast_OA_Region_Id__c, UserRole.Name, Profile.Name FROM User WHERE Id =: UserInfo.getUserId()];
        UserWrapper userWrap = new UserWrapper(userDetail);
        controller.userInfo = JSON.serialize(userWrap);
    }

    public class UserWrapper {
        public String userName;
        public String userId;
        public String userForecastOARegion;
        public String userForecastOARegionId;
        public String userRole;
        public String userProfile;

        public UserWrapper(User user) {
            this.userName = user.Name;
            this.userId = user.Id;
            this.userForecastOARegion = user.Forecast_OA_Region_Name__c;
            this.userForecastOARegionId = user.Forecast_OA_Region_Id__c;
            this.userRole = user.UserRole.Name;
            this.userProfile = user.Profile.Name;
        }
    }
}
Raj VakatiRaj Vakati
Try this
 
@isTest
public class ForecastArchiveControllerTest {
@isTest static void testForecastArch(){
	System.Test.startTest() ; 
	
	UserRole r = new UserRole(DeveloperName = 'MyCustomRole', Name = 'My Role');
insert r;


	  Profile pf= [Select Id from profile where Name='System Administrator']; 
        
        String orgId=UserInfo.getOrganizationId(); 
        String dateString=String.valueof(Datetime.now()).replace(' ','').replace(':','').replace('-','') ;
        Integer RandomId=Integer.valueOf(Math.rint(Math.random()*1000000)); 
        String uniqueName=orgId+dateString+RandomId; 
        User uu=new User(firstname = 'ABC', 
                         lastName = 'XYZ', 
                         email = uniqueName + '@test' + orgId + '.org', 
                         Username = uniqueName + '@test' + orgId + '.org', 
                         EmailEncodingKey = 'ISO-8859-1', 
                         Alias = uniqueName.substring(18, 23), 
                         TimeZoneSidKey = 'America/Los_Angeles', 
                         LocaleSidKey = 'en_US', 
						 Forecast_OA_Region_Name__c='Test' ,
						 Forecast_OA_Region_Id__c ='213123',
						  UserRoleId = r.Id ,
                         LanguageLocaleKey = 'en_US', 
                         ProfileId = pf.Id
                        ); 
        
        
        insert uu
		
		System.runAs(uu){
			
			
			ForecastArchiveController  con = new ForecastArchiveController () ;
			
			
			
		}
	
	
	
		System.Test.stopTest() ; 

	 
}
}