Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Hey i am new to salesforce. I write an apex trigger in lead.Whenever any lead is converted type picklist(standard field) in opportunity object has to updated with new-business.I had successfully wrote trigger for this and it handle bulk records also.My problem is i write a test class for this apex trigger it run successfully but i didn't get any code coverage for my trigger where i had done mistake.

my apex trigger

trigger trigMapFields on Lead (before update)  {
public opportunity con;
List<Id> leadStatus= new List<Id>();
      for(Lead lead:System.Trigger.new) 
      {
          if (lead.IsConverted) 
          {
            leadStatus.add(lead.ConvertedOpportunityId);
          }
      } 
List<Opportunity> opps=[select Id from Opportunity WHERE Opportunity.Id IN:leadStatus];
      for(Opportunity o:opps) 
      {
       o.Type='New Business';
      }
     update opps;
}

My apex test class

@isTest
public class testLeadConvertMapFields { 
static testMethod void trigTest() {

    // Create dummy lead
    Lead testLead = new Lead(Company='Test Lead',FirstName='John',LastName='Doe',Status='Open - Not Contacted');
    insert testLead;

    // Create dummy conversion
    Database.LeadConvert lc = new database.LeadConvert();
    lc.setLeadId(testLead.id);
    lc.setConvertedStatus('Closed - Converted');
    Database.LeadConvertResult lcr = Database.convertLead(lc);

    // Make sure conversion was successful
    System.assert(lcr.isSuccess());

    // Test Opportunity "Status" field update
    Opportunity testCon = [SELECT Type FROM Opportunity WHERE Opportunity.Id = :lcr.getOpportunityId()];
    System.assertEquals(testCon.Type,'New Business');
  }
 }

I think i wrote something wrong in test class by checking status field

share|improve this question
1  
run all test and then check coverage. Sometime DC does not display correct code coverage. – Tushar Sharma Feb 1 at 5:51
    
what is your issue.. are you getting any error or just your code coverage is always zero ? or check this salesforce.stackexchange.com/questions/104204/… – Ratan Feb 1 at 5:52
    
Hey Thanks buddy thanks for sharing knowledge you saved my lot of time bro @Tushar Sharma.. – Pavan tej Feb 1 at 5:53
    
@user2185482 if this works for you. Then you can accept my answer and close this question. – Tushar Sharma Feb 1 at 5:55
up vote 4 down vote accepted

Run all test and then check coverage. Sometime DC does not display correct code coverage.

It will solve your problem.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.