2
 trigger leadupdatecontact on Lead(after update){
    list<contact> con=new list<contact>();
   for(Lead le :trigger.new){     
         contact co=new contact();       
 if(le.convertedcontactid != NULL&&le.description!= Null&&co.description!=le.description)  {   
        co.description=le.description; 
        co.id=le.convertedcontactid; 
        con.add(co);
       }
     }
 update con;
}

this is the i wrote.

  @istest(seealldata=true) 
      public class testleadupdatecontact{ 

         static testMethod void testleadupdatecontact(){ 
            contact co=new contact(Lastname='Deep',description=''); 
            insert co; 
            lead l=new lead(Lastname='deep',custom__c=true,company='tejjjjj'); 
            insert l; l.id='00QN00000011W3G'; 
            update l; 
            co.Lastname='Deep'; 
            co.id='003N0000007CLdv'; 
            l.description=co.description; 
            update co; 
            } 
         } 

i have many possible ways ,but it is not showing the code coverage can any body send me the body of this test case

8
  • hi mohit i wrote one test for this one ,it is showing 83% code coverage in sandbox ,but while deploying in production it is showing that atleast one 1% is required for deploying.why it is not taking that 83% code coverage .do you have any idea
    – Teja
    Nov 14, 2013 at 7:08
  • can you post your test class ? Nov 14, 2013 at 7:18
  • @istest(seealldata=true) public class testleadupdatecontact{ static testMethod void testleadupdatecontact(){ contact co=new contact(Lastname='Deep',description=''); insert co; lead l=new lead(Lastname='deep',custom__c=true,company='tejjjjj'); insert l; l.id='00QN00000011W3G'; update l; co.Lastname='Deep'; co.id='003N0000007CLdv'; l.description=co.description; update co; } }
    – Teja
    Nov 14, 2013 at 7:22
  • i have edited a lot currently i am having only this code
    – Teja
    Nov 14, 2013 at 7:22
  • 1
    Any way i am learning one by one,good to better and better to best.Thank you for your valuable suggestions
    – Teja
    Nov 14, 2013 at 7:50

1 Answer 1

3

Obviously for this question i dont see any point in writing the test code myself ,but here is the hint on how to proceed

A lead has to be converted into the existing contact in test class

Test.startTest();

    Database.LeadConvert lc = new database.LeadConvert();
    lc.setLeadId(lead.id);
    lc.setDoNotCreateOpportunity(false); //**IMPORTANT METHOD HERE**
    lc.setAccountId(account.id);
    lc.setContactId(contact.id);

    LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
    lc.setConvertedStatus(convertStatus.MasterLabel);
    Database.LeadConvertResult lcr = Database.convertLead(lc);

    Test.stopTest();

Obviously a sample account,contact and lead has to be created and assumed in above testcode ,then description has to be changed for contact and lead as per the business logic of above class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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