+ Start a Discussion
NK@BITNK@BIT 

Test class for apex controller

Please help me in writing test class for this controller..

public with sharing class TimeCardController{

    public Timecard__c timecard1{get; set;}
    public List<Resource__c> resource{get; set;}
    public String passcode{get; set;}
    public Boolean Match{get; set;}
    public Boolean NoMatch{get; set;}
    public Boolean readValue1{get;set;} 
    public String resourceName{get;set;} 
  
    Public TimeCardController(){
        timecard1 = new Timecard__c();
        readValue1 =true;
    }
  
   Public void timecardsignin(){
       resource=new List<Resource__c>();
       Match=false;
       NoMatch=false;
       readValue1 =false;
      
       resource=[select Id, Name, Passcode__c from Resource__c where Id=:timecard1.Resource__c AND Passcode__c=:passcode];
      
       if(resource.size()>0)
       {
           Match=true;
       }
       else
       {
           NoMatch=true;
       }
   }
  
    public PageReference timeCard(){
        Timecard__c tc=new Timecard__c();
        tc.Resource__c=timecard1.Resource__c;
        tc.Project__c=timecard1.Project__c;
        tc.Activity_Date__c=timecard1.Activity_Date__c;
        tc.Project_Task__c=timecard1.Project_Task__c;
        tc.Activity_Description__c=timecard1.Activity_Description__c;
        tc.Hours__c=timecard1.Hours__c;
      
        insert tc;
        resourceName=resource[0].name;
        readValue1 = true;
        Match=false;
       
        apexpages.Message msg = new Apexpages.Message(ApexPages.Severity.Info,'Time Card Successfully Updated for '+ resourceName);
        apexpages.addmessage(msg);
        timecard1.clear();
        return null;
       
    }  
    public PageReference doCancel()
    {
        PageReference pageRef = new PageReference('http://crmdev-bitorder.cs6.force.com/timecard');
        pageRef.setRedirect(true);
        return pageRef;
    }

  }
Sonam_SFDCSonam_SFDC
Hi,

I would encourage  you to go through the following test sample code which explains how you can test a given class :
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_testing_example.htm

Once you write the code and face any issues/errors - you can post the questions on the community to get help!