• abhilash reddy 49
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 4
    Replies
Hi, I wrote Test Class for below Apex Class But I am getting only 67% code coverage how can i achieve 100% code coverage...Apex class and corresponding test class given below....

global class SiteLoginController1 {
    public String username     {get; set;}
    public String password     {get; set;}
    public String EmpName      {get;set;}
   

    
    
    global SiteLoginController1 () {}
    
    public boolean ErrorMsg{get;set;}
    public PageReference CheckUserPswd() {
        system.debug('----username----'+ username);
        system.debug('----password----'+ password);
        List<Employee__c> empList = [Select id, Name, User_Name__c,Password__c from Employee__c where User_Name__c =: username];
        system.debug('----empList----'+ empList);
        if(empList.size()>0){
            if(empList[0].Password__c == password){
                ErrorMsg = False;
                system.debug('----'+ErrorMsg);
                
                 EmpName=empList[0].name;
                system.debug('----'+EmpName);
               //create a new page to enter task and associate here and also do the log off
              PageReference pr=new PageReference('/apex/TimeSheetManagement?name='+EmpName);
                system.debug('-----'+pr);
                
                pr.setRedirect(true);
                return pr;              
            }
            else{
                ErrorMsg = true;
                return null;
            }
        }
        else{
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'No Active Employee record found with provided username.Please contact your administrator'));
            return null;
        }
    }  
    
    Public Pagereference UpdatePasswordPage(){
        PageReference newPage;
        newPage = new PageReference('/apex/Forgot_Password_VF_Page');
        newPage.setRedirect(true);
        return newPage; 
    } 
    Public Pagereference ChangePassword(){
        PageReference newPage;
        EmpName=username ;
        system.debug('----'+EmpName);
        if(String.isEmpty(EmpName)){
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Please Enter The  User Name'));
            return null;
        }else{
            List<Employee__c> empList = [Select id, Name, User_Name__c,Password__c from Employee__c where User_Name__c =: EmpName];
            system.debug('----'+empList);
            if(empList.size()==0){
                ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Please Enter The Valid User Name'));
                return null;
            }else{
                
                EmpName=empList[0].name;
                 system.debug('----'+EmpName);
                newPage = new PageReference('/apex/Change_Password_Vf_Page?name='+EmpName);
                newPage.setRedirect(true);
                 return newPage; 
            }
                
            
        }
        
        
    } 
    
}

----------------------------------------------------------------------My Test Class is-------------------------------------
@isTest
private class SiteLoginController1Test {

@isTest
private static void testSiteLogin() {

Employee__c e = new Employee__c() ;
e.Name ='Test' ; 

// Add Pther required fields  if any
insert e ;
 
    
   SiteLoginController1 controller = new SiteLoginController1();
   controller.CheckUserPswd();
   controller.UpdatePasswordPage();
   controller.ChangePassword();
   
  

 }


}
How to Write Test Class For Below Controller....
global class SiteLoginController1 {
    public String username     {get; set;}
    public String password     {get; set;}
    public String EmpName      {get;set;}
   

    
    
    global SiteLoginController1 () {}
    
    public boolean ErrorMsg{get;set;}
    public PageReference CheckUserPswd() {
        system.debug('----username----'+ username);
        system.debug('----password----'+ password);
        List<Employee__c> empList = [Select id, Name, User_Name__c,Password__c from Employee__c where User_Name__c =: username];
        system.debug('----empList----'+ empList);
        if(empList.size()>0){
            if(empList[0].Password__c == password){
                ErrorMsg = False;
                system.debug('----'+ErrorMsg);
                
                 EmpName=empList[0].name;
                system.debug('----'+EmpName);
               //create a new page to enter task and associate here and also do the log off
              PageReference pr=new PageReference('/apex/TimeSheetManagement?name='+EmpName);
                system.debug('-----'+pr);
                
                pr.setRedirect(true);
                return pr;              
            }
            else{
                ErrorMsg = true;
                return null;
            }
        }
        else{
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'No Active Employee record found with provided username.Please contact your administrator'));
            return null;
        }
    }  
    
    Public Pagereference UpdatePasswordPage(){
        PageReference newPage;
        newPage = new PageReference('/apex/Forgot_Password_VF_Page');
        newPage.setRedirect(true);
        return newPage; 
    } 
    Public Pagereference ChangePassword(){
        PageReference newPage;
        EmpName=username ;
        system.debug('----'+EmpName);
        if(String.isEmpty(EmpName)){
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Please Enter The  User Name'));
            return null;
        }else{
            List<Employee__c> empList = [Select id, Name, User_Name__c,Password__c from Employee__c where User_Name__c =: EmpName];
            system.debug('----'+empList);
            if(empList.size()==0){
                ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Please Enter The Valid User Name'));
                return null;
            }else{
                
                EmpName=empList[0].name;
                 system.debug('----'+EmpName);
                newPage = new PageReference('/apex/Change_Password_Vf_Page?name='+EmpName);
                newPage.setRedirect(true);
                 return newPage; 
            }
                
            
        }
        
        
    } 
    
}
1.)I have a Checkbox field called "Best Contact" in contact object.
2.)I have a checkBox field called "Contains Best Contact" in account object.
My requirement is if atlest one contact checkbox field (Best Contact)is true then we have to make corresponding Account checkbox filed(Contains Best Contact)to true
How to Write Test Class For Below Controller....
global class SiteLoginController1 {
    public String username     {get; set;}
    public String password     {get; set;}
    public String EmpName      {get;set;}
   

    
    
    global SiteLoginController1 () {}
    
    public boolean ErrorMsg{get;set;}
    public PageReference CheckUserPswd() {
        system.debug('----username----'+ username);
        system.debug('----password----'+ password);
        List<Employee__c> empList = [Select id, Name, User_Name__c,Password__c from Employee__c where User_Name__c =: username];
        system.debug('----empList----'+ empList);
        if(empList.size()>0){
            if(empList[0].Password__c == password){
                ErrorMsg = False;
                system.debug('----'+ErrorMsg);
                
                 EmpName=empList[0].name;
                system.debug('----'+EmpName);
               //create a new page to enter task and associate here and also do the log off
              PageReference pr=new PageReference('/apex/TimeSheetManagement?name='+EmpName);
                system.debug('-----'+pr);
                
                pr.setRedirect(true);
                return pr;              
            }
            else{
                ErrorMsg = true;
                return null;
            }
        }
        else{
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'No Active Employee record found with provided username.Please contact your administrator'));
            return null;
        }
    }  
    
    Public Pagereference UpdatePasswordPage(){
        PageReference newPage;
        newPage = new PageReference('/apex/Forgot_Password_VF_Page');
        newPage.setRedirect(true);
        return newPage; 
    } 
    Public Pagereference ChangePassword(){
        PageReference newPage;
        EmpName=username ;
        system.debug('----'+EmpName);
        if(String.isEmpty(EmpName)){
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Please Enter The  User Name'));
            return null;
        }else{
            List<Employee__c> empList = [Select id, Name, User_Name__c,Password__c from Employee__c where User_Name__c =: EmpName];
            system.debug('----'+empList);
            if(empList.size()==0){
                ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Please Enter The Valid User Name'));
                return null;
            }else{
                
                EmpName=empList[0].name;
                 system.debug('----'+EmpName);
                newPage = new PageReference('/apex/Change_Password_Vf_Page?name='+EmpName);
                newPage.setRedirect(true);
                 return newPage; 
            }
                
            
        }
        
        
    } 
    
}
1.)I have a Checkbox field called "Best Contact" in contact object.
2.)I have a checkBox field called "Contains Best Contact" in account object.
My requirement is if atlest one contact checkbox field (Best Contact)is true then we have to make corresponding Account checkbox filed(Contains Best Contact)to true
Hello everyone! hope you are fine :)

Right now I´m developing a page that contains filters like the add campaign members:
User-added image
I do almost everything, but I still have problems with the filters, because the costumer wants the same behavior that have that page. I need to render the operators for the specific data type selected and if it is a look up I must allow the user to search with the magnifying glass button.

If somebody has a good idea or had a similar code, please lend me know it, I'm desperate.

Thank you so much! :)

Have a nice day!