• jhugger
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies

It's almost my first test class, please anyone can help me.

I get 0% covered by test class for my custom controller:

My class:

 

public with sharing class MyCustomLookupController {

   public Influencer__c Influencer { get; set; }

   public Id accountplanid { get; set; }
      
   public MyCustomLookupController () {
       accountplanid = System.currentPageReference().getParameters().get('id');
       Influencer = new Influencer__c(Account_Plan__c = accountplanid );
   }
    

 
 

    public PageReference save() {
      
        Contact c = [SELECT Job_title__c,name FROM Contact WHERE Id = :Influencer.Contact__c];
        
        Influencer.Title__c = c.Job_title__c;
        influencer.name=c.name;
        insert Influencer;
        PageReference acctPage = new PageReference('/' + Influencer.id);
        acctPage.setRedirect(true);
        return acctPage;
    }
    
    
       public PageReference cancel() {
      
        PageReference aPage = new PageReference('/' + accountplanid);
        aPage.setRedirect(true);
        return aPage;
    }
       
 
}

 

My test class:

@isTest 
private class MyCustomLookupControllerTestClass {
    static testMethod void validate() {


    PageReference pageRef = Page.MyCustomLookup; 
    Test.setCurrentPage(pageRef);
    
    // Create a new account object.
    Account testAccount = new Account(Name = 'TestAccount');
    testAccount.Red_Account_End_Date__c=date.today();
    testAccount.Red_Account_Reason__c='reason';
    testAccount.Red_Account__c= true;
    insert testAccount;
  
    
    //CREATE TEST ACCOUNT PLAN
     Account_Plan__c accountplan=new Account_Plan__c ();
     accountplan.account__c=testaccount.id;
     insert accountplan;
    
    //CREATE TEST CONTACT
     Contact contact = new contact(lastname='lname');
     contact.Job_title__c='salesrep';
     insert contact; 
     Contact contact2 = new contact(lastname='lname');
     insert contact2;  
    
    //CREATE TEST INFLUENCER
       Influencer__C influencertest = new Influencer__c();
       influencertest.Account_Plan__c= accountplan.id;
       Influencertest.Title__c = contact.Job_title__c;
        influencertest.contact__c=contact2.id;
       insert influencertest;     
         
        
   }

     }

 

 

Sorry, I have to learn a lots of things.

Thank you,Br.