• prachi barahate
  • NEWBIE
  • 20 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 3
    Replies
Please help in writing test class.I have tried writing it,and has achieved 8% coverage.I m stusck how to cover if statement.Please guide me..
Visualforce page:
<apex:page controller="createJAfornewCand">
 <apex:form >    
         <apex:pageblock title="New Candidate">
         <apex:pageBlockButtons >
             <apex:commandButton action="{!save}" value="Save"/>
         </apex:pageBlockButtons>
             <apex:pageBlockSection title="Information" collapsible="false"  showHeader="true">
                 <apex:inputField value="{!c.First_Name__c}"/>
                 <apex:inputField value="{!c.Last_Name__c}"/>
                 <apex:inputField value="{!c.Years_of_Experience__c}"/>  
                 <apex:inputField value="{!c.SSN__c}"/>              
                 <apex:inputField value="{!c.Technology__c}"/>                  
                 <apex:inputField value="{!c.Phone__c}"/>
                 <apex:inputField value="{!c.Mobile__c}"/>
                 <apex:inputField value="{!c.Email__c}"/>
             </apex:pageBlockSection>    
         </apex:pageblock>    
 </apex:form>
</apex:page>

Controller:
public class createJAfornewCand
{  
    Candidate__c c;  
    List<Position__c> p;
    public Candidate__c getC()
    {
        if(c==null)
            c=new Candidate__c();
       return c; 
    }
  
    public void setC(Candidate__c v)
    {
        v=c;
    } 
     
    public PageReference save()
    {
       insert c;
       Decimal d=c.Years_of_Experience__c;
       if(c.Technology__c=='Java')
          p =[select id from position__c where Experience_Required__c<= :d and java__c=true];
           
       if(c.Technology__c=='Apex')
         p =[select id from position__c where Experience_Required__c<= :d and apex__c=true];
          
       if(c.Technology__c=='C#')
         p =[select id from position__c where Experience_Required__c<= :d and c__c=true];
         
        if(p.size()>0)
        {
            for(Position__c pos:p)
            {
                Job_application__c ja =new Job_application__c ();
                ja.position__c=pos.id;
                ja.candidate__c=c.id;
                insert ja;
            }
        }    
     
       
        return null;
    }
}


Test class:
@isTest
public class conrollerTest
{
    static testmethod void createja()
    {
        Position__C p=new Position__C(Name='Tester',Experience_Required__c=9,java__c=true);
        insert p;
        Candidate__c c=new Candidate__C(First_Name__c='dd',Years_of_Experience__c=10,Technology__c='Java');
         
        Test.StartTest();
        
        PageReference pageRef = Page.createJAfornewCandidate;
        Test.setCurrentPage(pageRef);        
        createJAfornewCand con= new  createJAfornewCand();
         insert c;
      
        con.save();
           
         Job_Application__c js=[select id from Job_Application__c  where candidate__C= :c.id];
         System.assertEquals(js.position__c,p.id);
       
        Test.StopTest();      
        
    }
    
}
I had created a trigger on a custom object 'Job_application__c' as follows:
Trigger code:
trigger chk_no_of_appn_appliedTODAY on Job_Application__c (before insert,before update) 
{
    Integer n=[select count() from Job_Application__c where createddate=TODAY and CreatedById =:UserInfo.getUserId()];

    for(Job_Application__c j:Trigger.new)
    {
        if((j.createddate==date.today())&&(j.CreatedById==UserInfo.getUserId()))
        n+=1;-----------------1
        
           if(n>5)
            j.addError('you have exceeded today limit');------------------------2
    }

And had written test class like as :
Test Class :
@isTest
public class t2 
{
    static testmethod void check()
    {
        Profile p = [SELECT Id FROM Profile WHERE Name='Standard Employee'];

        User u2 = new User(Alias = 'Sailee', Email='Sailee@testorg.com',EmailEncodingKey='UTF-8', 
                            LastName='Testing', LanguageLocaleKey='en_US', 
                            LocaleSidKey='en_US', ProfileId = p.Id,
                          TimeZoneSidKey='America/Los_Angeles', UserName='Sailee@testorg.com');
        insert u2 ;
        
          
            
           System.runAs(u2)
           {  
               Position__c pos= new Position__c(Name='vb_4');
               insert pos;
           
               Candidate__C c= new Candidate__C(First_name__c='Prachci');
               insert c;
               for(integer i=0;i<5;i++)
               {
                    Job_Application__c  j =new Job_Application__c();
                    j.position__C=pos.Id;
                    j.Candidate__c=c.Id;                    
                    insert j;
                   
               }
               try
               {    
                   Test.StartTest(); 
                    
                   job_Application__c  j1 =new Job_Application__c(position__C=pos.Id,Candidate__c=c.Id);
                   insert j1;                      
                   Test.StopTest();
               }
               catch(DMLException e)
               {
                   System.assert(e.getMessage().contains('you have exceeded today limit'));
               }
               
           }

    }
}
This class is giving 71% coverage and highlighting line marked---1  and --2  as not traced in results.
Please me in modifying code to achieve 100% coverage.
I am writting a simple code in visualforce using standard list controller and inline edit support.Inline edit support is working properly .
But can able to save records.
Following is the code:
<apex:page standardController="Leave__c" recordSetVar="l">
<apex:form >
    <apex:pageBlock title="Display leaves records">
        <apex:pageBlockTable value="{!l}" var="e">
            <apex:column value="{!e.Employee__r.First_Name__c}"/>
            <apex:column value="{!e.From_Date__c}"/>
            <apex:column value="{!e.Leave_Type__c}"/>
            <apex:column value="{!e.To_Date__c}"/>   
            <apex:column value="{!e.Number_of_days__c}"/>   
            <apex:inlineEditSupport />                         
        </apex:pageBlockTable>  
  
         <apex:pageBlockButtons >
           <apex:commandButton value="Previous" action="{!previous}"/>
           <apex:commandButton value="Next" action="{!next}"/>
           <apex:commandButton value="first" action="{!first}"/>
           <apex:commandButton value="last" action="{!last}"/> <br/>       
           <apex:commandButton value="save" action="{!quickSave}"/>
        </apex:pageBlockButtons>
     </apex:pageBlock>   
</apex:form>
</apex:page>

M I missing something in this code.

Also when InlineditSupport is placed between column tags for every feild .Save is wroking fine.

But my confusion is why my above code is not working as i saw such type of codes working in many online tutorials examples.
 
Hi,
I am very much new to the salesforce.

I am creating recruiting app using a following book
http://www.salesforce.com/us/developer/docs/fundamentals/salesforce_creating_on_demand_apps.pdf.
In its security and sharing data section I have created a user Cynthia Capobianco, and assigned standard user profile (give only read access to position object) ,also added her to CEO role of org.
But when I am logging through her login m only able to see only position tab which as per profile is totally correct,But my confusion in this ..she is also CEO of org then she should see all the object and records.
Is there any thing else need to be done to make her CEO to access full app??

Regards
Prachi
Please help in writing test class.I have tried writing it,and has achieved 8% coverage.I m stusck how to cover if statement.Please guide me..
Visualforce page:
<apex:page controller="createJAfornewCand">
 <apex:form >    
         <apex:pageblock title="New Candidate">
         <apex:pageBlockButtons >
             <apex:commandButton action="{!save}" value="Save"/>
         </apex:pageBlockButtons>
             <apex:pageBlockSection title="Information" collapsible="false"  showHeader="true">
                 <apex:inputField value="{!c.First_Name__c}"/>
                 <apex:inputField value="{!c.Last_Name__c}"/>
                 <apex:inputField value="{!c.Years_of_Experience__c}"/>  
                 <apex:inputField value="{!c.SSN__c}"/>              
                 <apex:inputField value="{!c.Technology__c}"/>                  
                 <apex:inputField value="{!c.Phone__c}"/>
                 <apex:inputField value="{!c.Mobile__c}"/>
                 <apex:inputField value="{!c.Email__c}"/>
             </apex:pageBlockSection>    
         </apex:pageblock>    
 </apex:form>
</apex:page>

Controller:
public class createJAfornewCand
{  
    Candidate__c c;  
    List<Position__c> p;
    public Candidate__c getC()
    {
        if(c==null)
            c=new Candidate__c();
       return c; 
    }
  
    public void setC(Candidate__c v)
    {
        v=c;
    } 
     
    public PageReference save()
    {
       insert c;
       Decimal d=c.Years_of_Experience__c;
       if(c.Technology__c=='Java')
          p =[select id from position__c where Experience_Required__c<= :d and java__c=true];
           
       if(c.Technology__c=='Apex')
         p =[select id from position__c where Experience_Required__c<= :d and apex__c=true];
          
       if(c.Technology__c=='C#')
         p =[select id from position__c where Experience_Required__c<= :d and c__c=true];
         
        if(p.size()>0)
        {
            for(Position__c pos:p)
            {
                Job_application__c ja =new Job_application__c ();
                ja.position__c=pos.id;
                ja.candidate__c=c.id;
                insert ja;
            }
        }    
     
       
        return null;
    }
}


Test class:
@isTest
public class conrollerTest
{
    static testmethod void createja()
    {
        Position__C p=new Position__C(Name='Tester',Experience_Required__c=9,java__c=true);
        insert p;
        Candidate__c c=new Candidate__C(First_Name__c='dd',Years_of_Experience__c=10,Technology__c='Java');
         
        Test.StartTest();
        
        PageReference pageRef = Page.createJAfornewCandidate;
        Test.setCurrentPage(pageRef);        
        createJAfornewCand con= new  createJAfornewCand();
         insert c;
      
        con.save();
           
         Job_Application__c js=[select id from Job_Application__c  where candidate__C= :c.id];
         System.assertEquals(js.position__c,p.id);
       
        Test.StopTest();      
        
    }
    
}
I am writting a simple code in visualforce using standard list controller and inline edit support.Inline edit support is working properly .
But can able to save records.
Following is the code:
<apex:page standardController="Leave__c" recordSetVar="l">
<apex:form >
    <apex:pageBlock title="Display leaves records">
        <apex:pageBlockTable value="{!l}" var="e">
            <apex:column value="{!e.Employee__r.First_Name__c}"/>
            <apex:column value="{!e.From_Date__c}"/>
            <apex:column value="{!e.Leave_Type__c}"/>
            <apex:column value="{!e.To_Date__c}"/>   
            <apex:column value="{!e.Number_of_days__c}"/>   
            <apex:inlineEditSupport />                         
        </apex:pageBlockTable>  
  
         <apex:pageBlockButtons >
           <apex:commandButton value="Previous" action="{!previous}"/>
           <apex:commandButton value="Next" action="{!next}"/>
           <apex:commandButton value="first" action="{!first}"/>
           <apex:commandButton value="last" action="{!last}"/> <br/>       
           <apex:commandButton value="save" action="{!quickSave}"/>
        </apex:pageBlockButtons>
     </apex:pageBlock>   
</apex:form>
</apex:page>

M I missing something in this code.

Also when InlineditSupport is placed between column tags for every feild .Save is wroking fine.

But my confusion is why my above code is not working as i saw such type of codes working in many online tutorials examples.