+ Start a Discussion
LAMCORPLAMCORP 

Test Class hitting 60% and cannot see which lines are being covered

Dear all,

 

Hoping someone can help here.

 

I am trying to write a trigger and class on Lead Convert to create a couple of custom object records.

 

The thing is I am only hitting 60% of coverage but the tested trigger is not showing in the

 

"Trigger code coverage" part? Any clues?

 

Also can someone help me with trying to achieve 100% please? Been trying for a couple of weeks to get this right now.

Thanks in advance

 

trigger LeadConvert2 on Lead (before update) {
     
      if (Trigger.new.size() == 1) {
      
        if (Trigger.old[0].isConverted == false && Trigger.new[0].isConverted == true) {
  
            if (Trigger.new[0].ConvertedAccountId != null) {

                Account a = [Select a.Id, a.Name, a.Description From Account a Where a.Id = :Trigger.new[0].ConvertedAccountId];
                a.Description = Trigger.new[0].Name;
                a.OwnerId = Trigger.new[0].Sales_ME1__c;
                update a;
 
                    // insert a Sales Monitor Line
                    Line_del__c obj = new Line_del__c();
                    obj.Name = a.Name;
                    obj.Team_s_Dept_s_del__c = Trigger.new[0].Sales_Team__c;
                    obj.ME1__c = Trigger.new[0].Sales_ME1__c;
                    obj.ME2__c = Trigger.new[0].Sales_ME2__c;
                    obj.DTR3__c = Trigger.new[0].Sales_DTR__c; 
                    obj.CU__c = Trigger.new[0].Sales_CU__c;
                    obj.Project_Completion_Date__c = Trigger.new[0].Sales_Project_Completion_Date__c;
                    obj.Division__c = Trigger.new[0].Sales_Division__c; 
                    obj.Utility__c = Trigger.new[0].Sales_Utility__c;
                    obj.Renewal_Acquisition__c = Trigger.new[0].Sales_Acquisition__c;
                    obj.Next_Action_Comments__c = Trigger.new[0].Sales_Next_Action_Comments__c;
                    obj.Notes__c = Trigger.new[0].Sales_Notes__c;                                        
                    obj.Linked_Account__c = a.Id;                    
                    insert obj;
                    
                    // insert a CR Monitor Line
                    if (Trigger.new[0].CR_ME1__c!= Null && Trigger.new[0].CR_DTR__c != Null) {
                    
                    Line_del__c obj2 = new Line_del__c();
                    obj2.Name = a.Name;
                    obj2.Team_s_Dept_s_del__c = 'a0P300000053prk';
                    obj2.ME1__c = Trigger.new[0].CR_ME1__c;
                    obj2.ME2__c = Trigger.new[0].CR_ME2__c;
                    obj2.DTR3__c = Trigger.new[0].CR_DTR__c; 
                    obj2.CU__c = Trigger.new[0].CR_CU__c;
                    obj2.Next_Action_Comments__c = Trigger.new[0].CR_Next_Action_Comments__c;
                    obj2.Notes__c = Trigger.new[0].CR_Notes__c;
                    obj2.Linked_Account__c = a.Id;
                    insert obj2;
                    
                    }
                    }
               }      
        }
 
}



@isTest
Private Class LeadConvert2{
static TestMethod void TestLeadConvert2(){

    Account accts = new Account(
    Name = 'TestCompany',
    OwnerId = '00530000004WakH' );
    insert accts;
    
    Line_del__c salesLine = new Line_del__c(
    Name = 'Test insert new Monitor Line',
    // FF Sales Team 
    Team_s_Dept_s_del__c = 'a0P300000053ps9', 
    ME1__c = '00530000004WakH',
    ME2__c = '00530000005dI0c',  
    DTR3__c = System.Today(),
    CU__c = System.Today(),
    Project_Completion_Date__c = System.Today(),
    Division__c = 'Util-Eyes',
    Utility__c = 'Gas',
    Renewal_Acquisition__c = 'Acquisition', 
    Next_Action_Comments__c = 'Test Next Action Text',
    Notes__c = 'Test Notes Text',
    Linked_Account__c = accts.Id   
    );

    Line_del__c CRLine = new Line_del__c (
    Name = 'Test insert new Monitor Line', 
    // CR Team 
    Team_s_Dept_s_del__c = 'a0P300000053prk', 
    ME1__c = '00530000004WakH', 
    ME2__c = '00530000005dI0c',      
    DTR3__c = System.Today(),
    CU__c = System.Today(),
    Next_Action_Comments__c = 'Test Next Action Text',
    Notes__c = 'Test Notes Text',
    Linked_Account__c = accts.Id   
    );
        
    test.StartTest();
    insert salesLine;
    insert CRLine;
    test.StopTest();
    
    }    
}
Best Answer chosen by Admin (Salesforce Developers) 
LAMCORPLAMCORP

Thanks Imran.. great help!!

 

I actually took out this line as it wasn't essential.

 

I also fixed the errors by prepopulating the Lead fields which I didn't do before.

 

The finished article which is now achieving 100% :)..looks like:

 

@isTest
Private Class LeadConvert2{
static TestMethod void TestLeadConvert2(){

    Lead ld = new Lead(Company = 'TestCompany', 
    LastName = 'Test', 
    OwnerId = '00530000004WakH',
    
    Sales_ME1__c = '00530000004WakH',
    Sales_ME2__c= '00530000005dI0c',
    Sales_DTR__c = System.Today(),
    Sales_CU__c = System.Today(),
    Sales_Project_Completion_Date__c = System.Today(),
    Sales_Division__c = 'Util-Eyes',
    Sales_Utility__c = 'Gas',
    Sales_Acquisition__c = 'Acquisition', 
    Sales_Next_Action_Comments__c = 'Test Next Action Text',
    Sales_Notes__c = 'Test Notes Text',
    
    CR_ME1__c = '00530000004WakH',
    CR_ME2__c = '00530000005dI0c',
    CR_DTR__c = System.Today(),
    CR_CU__c = System.Today()
    );
    insert ld;

    Database.LeadConvert lc = new database.LeadConvert();
    lc.setLeadId(ld.id);
    lc.doNotCreateOpportunity=true;
    LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
    lc.setConvertedStatus(convertStatus.MasterLabel);
    Database.LeadConvertResult lcr = Database.convertLead(lc);

    Account accts = new Account(
    Name = 'TestCompany',
    OwnerId = '00530000004WakH' );
    insert accts;
    
    Line_del__c salesLine = new Line_del__c(
    Name = 'Test insert new Monitor Line',
    // FF Sales Team 
    Team_s_Dept_s_del__c = 'a0P300000053ps9', 
    ME1__c = '00530000004WakH',
    ME2__c = '00530000005dI0c',  
    DTR3__c = System.Today(),
    CU__c = System.Today(),
    Project_Completion_Date__c = System.Today(),
    Division__c = 'Util-Eyes',
    Utility__c = 'Gas',
    Renewal_Acquisition__c = 'Acquisition', 
    Next_Action_Comments__c = 'Test Next Action Text',
    Notes__c = 'Test Notes Text',
    Linked_Account__c = accts.Id
    );

    Line_del__c CRLine = new Line_del__c (
    Name = 'Test insert new Monitor Line', 
    // CR Team 
    Team_s_Dept_s_del__c = 'a0P300000053prk', 
    ME1__c = '00530000004WakH', 
    ME2__c = '00530000005dI0c',      
    DTR3__c = System.Today(),
    CU__c = System.Today(),
    Next_Action_Comments__c = 'Test Next Action Text',
    Notes__c = 'Test Notes Text',
    Linked_Account__c = accts.Id   
    );
        
    test.StartTest();
    insert salesLine;
    insert CRLine;
    test.StopTest();
    
    }    
}

All Answers

imranrazaimranraza

Hi LAMCORP,

                              According to your Trigger code, you need to create a Lead Object in test class and convert it using code.

                            The trigger code will be automatically covered and you don't need to create the Object created in Trigger.

                             Like This:-

 

                            private class TestConvertLead{

                              @isTest

                              private static void runTest(){

                                Lead ld = new Lead(LastName = 'Test');

                                insert lead;

                                Database.LeadConvert lc = new database.LeadConvert();
                                lc.setLeadId(ld.id);
                                lc.doNotCreateOpportunity=true;
                                LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
                                 lc.setConvertedStatus(convertStatus.MasterLabel);
                                 Database.LeadConvertResult lcr = Database.convertLead(lc);

                        }

                     }

 


LAMCORPLAMCORP

Thanks Imran!!

This is great and worked. I can now see the lines covered. The only thing now is that it is not covering my custom objects.

Can you help me to understand why please?

 

imranrazaimranraza

Hi LAMCORP,

 In your code there may be problem of any exception in your code.

 Is there any exception showing on your page where you run your test class.

 If the exception is not showing on your page then add Debug and check there may be any exception.

 Because trigger code is covered at update a location and after that there is no condition that mean flow is straight  and the issue is Exception in your code.

 

Thanks

Imran

LAMCORPLAMCORP

Hi Imran,

 

You are probably right. The message & stack trace say;

 

I can't see where the ownerID could be blank?

   
  System.DmlException: ConvertLead failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, System.DmlException: Update failed. First exception on row 0 with id 00QQ00000074AVMMA2; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, LeadConvert2: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 001Q000000SMNT9IAP; first error: INVALID_CROSS_REFERENCE_KEY, Owner ID: owner cannot be blank: [OwnerId] Trigger.LeadConvert2: line 12, column 1: [] (System Code) : []Class.LeadConvert2.TestLeadConvert2: line 13, column 1
LAMCORPLAMCORP

The debug log shows as:

 

24.0 APEX_CODE,FINE;APEX_PROFILING,FINE;DB,INFO;VALIDATION,INFO;WORKFLOW,FINEST

10:53:37.122 (122464000)|EXECUTION_STARTED

10:53:37.122 (122501000)|CODE_UNIT_STARTED|[EXTERNAL]|01pQ000000061Jr|LeadConvert2.TestLeadConvert2

10:53:37.122 (122770000)|METHOD_ENTRY|[2]|01pQ000000061Jr|LeadConvert2.LeadConvert2()

10:53:37.122 (122845000)|METHOD_EXIT|[2]|LeadConvert2

10:53:37.123 (123104000)|DML_BEGIN|[6]|Op:Insert|Type:Lead|Rows:1

10:53:37.126 (126976000)|CODE_UNIT_STARTED|[EXTERNAL]|Validation:Lead:new

10:53:37.126 (126990000)|VALIDATION_RULE|03d30000000iuab|Preferred_Contact_Fax

10:53:37.127 (127216000)|VALIDATION_FORMULA|AND(ISPICKVAL( Preferred_to_be_contacted_by__c, "Fax - Complete Fax no"),

(ISBLANK( Fax )))|Preferred_to_be_contacted_by__c=null , Fax=null

10:53:37.127 (127225000)|VALIDATION_PASS

10:53:37.127 (127228000)|VALIDATION_RULE|03d30000000iual|Preferred_Contact_Post

10:53:37.127 (127404000)|VALIDATION_FORMULA|AND(

ISPICKVAL(Preferred_to_be_contacted_by__c, "Post - Complete Address"),

OR(

(ISBLANK(Street)),

(ISBLANK( PostalCode))))|Street=null , PostalCode=null , Preferred_to_be_contacted_by__c=null

10:53:37.127 (127415000)|VALIDATION_PASS

10:53:37.127 (127417000)|VALIDATION_RULE|03d30000000itur|Mobile_must_be_11_digits

10:53:37.127 (127527000)|VALIDATION_FORMULA|AND(

NOT(

ISBLANK(MobilePhone)),

LEN(MobilePhone) <> 11

)|MobilePhone=null

10:53:37.127 (127534000)|VALIDATION_PASS

10:53:37.127 (127538000)|CODE_UNIT_FINISHED|Validation:Lead:new

10:53:37.259 (259222000)|CODE_UNIT_STARTED|[EXTERNAL]|Workflow:Lead

10:53:37.273 (273246000)|WF_RULE_EVAL_BEGIN|Assignment

10:53:37.273 (273273000)|WF_RULE_EVAL_BEGIN|Response

10:53:37.273 (273281000)|WF_RULE_EVAL_BEGIN|Workflow

10:53:37.273 (273307000)|WF_CRITERIA_BEGIN|[New Business Record: Test 00QQ00000074ATy]|NB - 1. Contact Details Uncheck|01Q30000000VKKT|ON_CREATE_OR_TRIGGERING_UPDATE

10:53:37.277 (277027000)|WF_RULE_FILTER|[New Business Record : Email equals null]

10:53:37.277 (277041000)|WF_RULE_EVAL_VALUE|null

10:53:37.277 (277047000)|WF_CRITERIA_END|true

10:53:37.278 (278156000)|WF_CRITERIA_BEGIN|[New Business Record: Test 00QQ00000074ATy]|NB - Inital Call Check 2|01Q30000000VKHt|ON_ALL_CHANGES

10:53:37.278 (278577000)|WF_FORMULA|Formula:OR(

Util_Eyes__c = true,

Energ_eyes1__c = true,

Real_Eyes__c  = true)|Values:Energ_eyes1__c=0, Real_Eyes__c=0, Util_Eyes__c=0

10:53:37.278 (278585000)|WF_CRITERIA_END|false

10:53:37.278 (278596000)|WF_CRITERIA_BEGIN|[New Business Record: Test 00QQ00000074ATy]|NB - 5. Consumption / Revenue Uncheck|01Q30000000VKPi|ON_CREATE_OR_TRIGGERING_UPDATE

10:53:37.279 (279261000)|WF_FORMULA|Formula:Earning_Potential2__c +  AUTO_Energ_eyes_Earnings__c < 1|Values:Earning_Potential2__c=0.00, AUTO_Energ_eyes_Earnings__c=0

10:53:37.279 (279269000)|WF_CRITERIA_END|true

10:53:37.279 (279285000)|WF_CRITERIA_BEGIN|[New Business Record: Test 00QQ00000074ATy]|NB - Threshold Status - Blank|01Q30000000Va6x|ON_ALL_CHANGES

10:53:37.279 (279518000)|WF_FORMULA|Formula:(Earning_Potential2__c +  AUTO_Energ_eyes_Earnings__c = 0)|Values:Earning_Potential2__c=0.00, AUTO_Energ_eyes_Earnings__c=0

10:53:37.279 (279526000)|WF_CRITERIA_END|true

10:53:37.279 (279540000)|WF_CRITERIA_BEGIN|[New Business Record: Test 00QQ00000074ATy]|NB - 6. Sales Line Check|01Q30000000Va6O|ON_ALL_CHANGES

10:53:37.279 (279803000)|WF_FORMULA|Formula:AND(

NOT(ISBLANK( Sales_Team__c )),

NOT(ISBLANK( Sales_ME1__c )),

NOT(ISBLANK( Sales_DTR__c )))|Values:Sales_Team__c=null, Sales_DTR__c=null, Sales_ME1__c=null

10:53:37.279 (279811000)|WF_CRITERIA_END|false

10:53:37.279 (279822000)|WF_CRITERIA_BEGIN|[New Business Record: Test 00QQ00000074ATy]|NB - 3. Lead Source / Affiliate Uncheck|01Q30000000VKQl|ON_ALL_CHANGES

10:53:37.279 (279841000)|WF_RULE_FILTER|[New Business Record : New Business Source ® equals null]

10:53:37.279 (279849000)|WF_RULE_EVAL_VALUE|null

10:53:37.279 (279852000)|WF_CRITERIA_END|true

10:53:37.279 (279861000)|WF_CRITERIA_BEGIN|[New Business Record: Test 00QQ00000074ATy]|NB - 1. Contact Details Check|01Q30000000VKHo|ON_ALL_CHANGES

10:53:37.279 (279895000)|WF_RULE_FILTER|[New Business Record : Company Name ® not equal to null]

AND [New Business Record : Last Name ® not equal to null]

AND [New Business Record : Phone ® not equal to null]

10:53:37.279 (279904000)|WF_RULE_EVAL_VALUE|TestCompany

10:53:37.279 (279908000)|WF_RULE_EVAL_VALUE|Test

10:53:37.279 (279912000)|WF_RULE_EVAL_VALUE|null

10:53:37.279 (279915000)|WF_CRITERIA_END|false

10:53:37.279 (279921000)|WF_CRITERIA_BEGIN|[New Business Record: Test 00QQ00000074ATy]|NB - 5. Consumption / Revenue Check|01Q30000000VKPd|ON_CREATE_OR_TRIGGERING_UPDATE

10:53:37.280 (280159000)|WF_FORMULA|Formula:Earning_Potential2__c + AUTO_Energ_eyes_Earnings__c > 0|Values:Earning_Potential2__c=0.00, AUTO_Energ_eyes_Earnings__c=0

10:53:37.280 (280167000)|WF_CRITERIA_END|false

10:53:37.280 (280177000)|WF_CRITERIA_BEGIN|[New Business Record: Test 00QQ00000074ATy]|NB - Threshold Status - Below|01Q30000000Va6s|ON_ALL_CHANGES

10:53:37.280 (280518000)|WF_FORMULA|Formula:Earning_Potential2__c + AUTO_Energ_eyes_Earnings__c > 0

&&

OR(

Earning_Potential2__c +  AUTO_Energ_eyes_Earnings__c < 5000,

AND(Earning_Potential2__c = 0, AUTO_Energ_eyes_Earnings__c < 1000))|Values:Earning_Potential2__c=0.00, AUTO_Energ_eyes_Earnings__c=0

10:53:37.280 (280528000)|WF_CRITERIA_END|false

10:53:37.280 (280538000)|WF_CRITERIA_BEGIN|[New Business Record: Test 00QQ00000074ATy]|NB - 6. Sales Line Uncheck|01Q30000000Va6Y|ON_ALL_CHANGES

10:53:37.280 (280762000)|WF_FORMULA|Formula:OR(

ISBLANK( Sales_Team__c ),

(ISBLANK( Sales_ME1__c)),

(ISBLANK( Sales_DTR__c )))|Values:Sales_Team__c=null, Sales_DTR__c=null, Sales_ME1__c=null

10:53:37.280 (280770000)|WF_CRITERIA_END|true

10:53:37.280 (280784000)|WF_CRITERIA_BEGIN|[New Business Record: Test 00QQ00000074ATy]|NB - 3. Lead Source / Affiliate Check|01Q30000000VKn6|ON_ALL_CHANGES

10:53:37.280 (280801000)|WF_RULE_FILTER|[New Business Record : New Business Source ® not equal to null]

10:53:37.280 (280808000)|WF_RULE_EVAL_VALUE|null

10:53:37.280 (280811000)|WF_CRITERIA_END|false

10:53:37.280 (280817000)|WF_CRITERIA_BEGIN|[New Business Record: Test 00QQ00000074ATy]|NB - 4. Initial Email / Letter / Fax|01Q30000000VKPn|ON_ALL_CHANGES

10:53:37.280 (280862000)|WF_RULE_FILTER|[New Business Record : Industry ® not equal to null]

AND [New Business Record : Initial Email / Letter / Fax Sent? ® equals true]

10:53:37.280 (280870000)|WF_RULE_EVAL_VALUE|null

10:53:37.280 (280873000)|WF_CRITERIA_END|false

10:53:37.280 (280879000)|WF_CRITERIA_BEGIN|[New Business Record: Test 00QQ00000074ATy]|NB - Threshold Status - Above|01Q30000000Va6d|ON_ALL_CHANGES

10:53:37.281 (281224000)|WF_FORMULA|Formula:OR(

Earning_Potential2__c >= 5000,

Earning_Potential2__c +  AUTO_Energ_eyes_Earnings__c >= 5000,

AND(Earning_Potential2__c = 0 ,AUTO_Energ_eyes_Earnings__c >= 1000))|Values:Earning_Potential2__c=0.00, AUTO_Energ_eyes_Earnings__c=0

10:53:37.281 (281235000)|WF_CRITERIA_END|false

10:53:37.281 (281245000)|WF_CRITERIA_BEGIN|[New Business Record: Test 00QQ00000074ATy]|NB - 4. Initial Email / Monitor Uncheck|01Q30000000VKPs|ON_ALL_CHANGES

10:53:37.281 (281307000)|WF_RULE_FILTER|[New Business Record : Industry ® equals null] OR

 [New Business Record : Initial Email / Letter / Fax Sent? ® equals false]

10:53:37.281 (281355000)|WF_RULE_EVAL_VALUE|null

10:53:37.281 (281360000)|WF_CRITERIA_END|true

10:53:37.281 (281373000)|WF_CRITERIA_BEGIN|[New Business Record: Test 00QQ00000074ATy]|NB - Inital Call UN-Check 2|01Q30000000VKHy|ON_ALL_CHANGES

10:53:37.281 (281584000)|WF_FORMULA|Formula:AND(

Util_Eyes__c = false,

Energ_eyes1__c = false,

Real_Eyes__c  = false)|Values:Energ_eyes1__c=0, Real_Eyes__c=0, Util_Eyes__c=0

10:53:37.281 (281595000)|WF_CRITERIA_END|true

10:53:37.281 (281619000)|WF_SPOOL_ACTION_BEGIN|Workflow

10:53:37.281 (281825000)|WF_ACTION| Field Update: 8;

10:53:37.281 (281837000)|WF_RULE_EVAL_BEGIN|Escalation

10:53:37.281 (281843000)|WF_RULE_EVAL_END

10:53:37.281 (281908000)|WF_ACTIONS_END| Field Update: 8;

10:53:37.281 (281914000)|CODE_UNIT_FINISHED|Workflow:Lead

10:53:37.282 (282656000)|DML_END|[6]

10:53:37.283 (283420000)|SOQL_EXECUTE_BEGIN|[11]|Aggregations:0|select Id, MasterLabel from LeadStatus where IsConverted = true limit 1

10:53:37.285 (285261000)|SOQL_EXECUTE_END|[11]|Rows:1

10:53:37.285 (285484000)|DML_BEGIN|[13]|Op:ConvertLead|Type:LeadConvertResult|Rows:1

10:53:37.642 (642139000)|CODE_UNIT_STARTED|[EXTERNAL]|01qQ00000004gW5|LeadConvert2 on Lead trigger event AfterUpdate for [00QQ00000074ATy]

10:53:37.642 (642731000)|SOQL_EXECUTE_BEGIN|[9]|Aggregations:0|select a.Id, a.Name, a.Description from Account a where a.Id = :tmpVar1

10:53:37.647 (647405000)|SOQL_EXECUTE_END|[9]|Rows:1

10:53:37.647 (647619000)|DML_BEGIN|[12]|Op:Update|Type:Account|Rows:1

10:53:37.653 (653393000)|DML_END|[12]

10:53:37.653 (653491000)|VF_PAGE_MESSAGE|Owner ID: owner cannot be blank

10:53:37.653 (653608000)|EXCEPTION_THROWN|[12]|System.DmlException: Update failed. First exception on row 0 with id 001Q000000SMNGiIAP; first error: INVALID_CROSS_REFERENCE_KEY, Owner ID: owner cannot be blank: [OwnerId]

10:53:37.655 (655098000)|FATAL_ERROR|System.DmlException: Update failed. First exception on row 0 with id 001Q000000SMNGiIAP; first error: INVALID_CROSS_REFERENCE_KEY, Owner ID: owner cannot be blank: [OwnerId]

 

Trigger.LeadConvert2: line 12, column 1

10:53:37.655 (655119000)|FATAL_ERROR|System.DmlException: Update failed. First exception on row 0 with id 001Q000000SMNGiIAP; first error: INVALID_CROSS_REFERENCE_KEY, Owner ID: owner cannot be blank: [OwnerId]

 

Trigger.LeadConvert2: line 12, column 1

10:53:37.696 (655129000)|CUMULATIVE_LIMIT_USAGE

10:53:37.696|LIMIT_USAGE_FOR_NS|(default)|

  Number of SOQL queries: 2 out of 100

  Number of query rows: 2 out of 50000

  Number of SOSL queries: 0 out of 20

  Number of DML statements: 3 out of 150

  Number of DML rows: 3 out of 10000

  Number of script statements: 12 out of 200000

  Maximum heap size: 0 out of 6000000

  Number of callouts: 0 out of 10

  Number of Email Invocations: 0 out of 10

  Number of fields describes: 0 out of 100

  Number of record type describes: 0 out of 100

  Number of child relationships describes: 0 out of 100

  Number of picklist describes: 0 out of 100

  Number of future calls: 0 out of 10

 

10:53:37.696|TOTAL_EMAIL_RECIPIENTS_QUEUED|0

10:53:37.696|STATIC_VARIABLE_LIST|

  double:MIN_NORMAL:0

  double:POSITIVE_INFINITY:0

  long:serialVersionUID:0

  Boolean:TRUE:0

  double:MIN_VALUE:0

  int:SIZE:0

  int[]:sizeTable:0

  char[]:DigitOnes:0

  char[]:DigitTens:0

  double:NaN:0

  double:NEGATIVE_INFINITY:0

  int:MIN_VALUE:0

  int:SIZE:0

  String:_static_EMPTY_KEY:0

  double:MAX_VALUE:0

  long:serialVersionUID:0

  int:MAX_EXPONENT:0

  int:MIN_EXPONENT:0

  Boolean:FALSE:0

  int:MAX_VALUE:0

  char[]:digits:0

  long:serialVersionUID:0

 

10:53:37.696|CUMULATIVE_LIMIT_USAGE_END

 

10:53:37.655 (655262000)|CODE_UNIT_FINISHED|LeadConvert2 on Lead trigger event AfterUpdate for [00QQ00000074ATy]

10:53:37.659 (659255000)|FATAL_ERROR|System.DmlException: Update failed. First exception on row 0 with id 00QQ00000074ATyMAM; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, LeadConvert2: execution of AfterUpdate

 

caused by: System.DmlException: Update failed. First exception on row 0 with id 001Q000000SMNGiIAP; first error: INVALID_CROSS_REFERENCE_KEY, Owner ID: owner cannot be blank: [OwnerId]

 

Trigger.LeadConvert2: line 12, column 1: []

 

(System Code)

 

10:53:37.662 (662229000)|FATAL_ERROR|System.DmlException: Update failed. First exception on row 0 with id 00QQ00000074ATyMAM; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, LeadConvert2: execution of AfterUpdate

 

caused by: System.DmlException: Update failed. First exception on row 0 with id 001Q000000SMNGiIAP; first error: INVALID_CROSS_REFERENCE_KEY, Owner ID: owner cannot be blank: [OwnerId]

 

Trigger.LeadConvert2: line 12, column 1: []

 

(System Code)

 

10:53:37.662 (662774000)|DML_END|[13]

10:53:37.662 (662873000)|EXCEPTION_THROWN|[13]|System.DmlException: ConvertLead failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, System.DmlException: Update failed. First exception on row 0 with id 00QQ00000074ATyMAM; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, LeadConvert2: execution of AfterUpdate

 

caused by: System.DmlException: Update failed. First exception on row 0 with id 001Q000000SMNGiIAP; first error: INVALID_CROSS_REFERENCE_KEY, Owner ID: owner cannot be blank: [OwnerId]

 

Trigger.LeadConvert2: line 12, column 1: []

 

(System Code)

: []

10:53:37.668 (668760000)|FATAL_ERROR|System.DmlException: ConvertLead failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, System.DmlException: Update failed. First exception on row 0 with id 00QQ00000074ATyMAM; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, LeadConvert2: execution of AfterUpdate

 

caused by: System.DmlException: Update failed. First exception on row 0 with id 001Q000000SMNGiIAP; first error: INVALID_CROSS_REFERENCE_KEY, Owner ID: owner cannot be blank: [OwnerId]

 

Trigger.LeadConvert2: line 12, column 1: []

 

(System Code)

: []

 

Class.LeadConvert2.TestLeadConvert2: line 13, column 1

10:53:37.671 (671163000)|FATAL_ERROR|System.DmlException: ConvertLead failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, System.DmlException: Update failed. First exception on row 0 with id 00QQ00000074ATyMAM; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, LeadConvert2: execution of AfterUpdate

 

caused by: System.DmlException: Update failed. First exception on row 0 with id 001Q000000SMNGiIAP; first error: INVALID_CROSS_REFERENCE_KEY, Owner ID: owner cannot be blank: [OwnerId]

 

Trigger.LeadConvert2: line 12, column 1: []

 

(System Code)

: []

 

Class.LeadConvert2.TestLeadConvert2: line 13, column 1

10:53:37.712 (671188000)|CUMULATIVE_LIMIT_USAGE

10:53:37.712|LIMIT_USAGE_FOR_NS|(default)|

  Number of SOQL queries: 1 out of 100

  Number of query rows: 1 out of 50000

  Number of SOSL queries: 0 out of 20

  Number of DML statements: 2 out of 150

  Number of DML rows: 2 out of 10000

  Number of script statements: 8 out of 200000

  Maximum heap size: 0 out of 6000000

  Number of callouts: 0 out of 10

  Number of Email Invocations: 0 out of 10

  Number of fields describes: 0 out of 100

  Number of record type describes: 0 out of 100

  Number of child relationships describes: 0 out of 100

  Number of picklist describes: 0 out of 100

  Number of future calls: 0 out of 10

 

10:53:37.712|TOTAL_EMAIL_RECIPIENTS_QUEUED|0

10:53:37.712|STATIC_VARIABLE_LIST|

  double:MIN_NORMAL:0

  double:POSITIVE_INFINITY:0

  long:serialVersionUID:0

  Boolean:TRUE:0

  double:MIN_VALUE:0

  int:SIZE:0

  int[]:sizeTable:0

  char[]:DigitOnes:0

  char[]:DigitTens:0

  double:NaN:0

  double:NEGATIVE_INFINITY:0

  int:MIN_VALUE:0

  int:SIZE:0

  String:_static_EMPTY_KEY:0

  double:MAX_VALUE:0

  long:serialVersionUID:0

  int:MAX_EXPONENT:0

  int:MIN_EXPONENT:0

  Boolean:FALSE:0

  int:MAX_VALUE:0

  char[]:digits:0

  long:serialVersionUID:0

 

10:53:37.712|CUMULATIVE_LIMIT_USAGE_END

 

10:53:37.671 (671288000)|CODE_UNIT_FINISHED|LeadConvert2.TestLeadConvert2

10:53:37.671 (671296000)|EXECUTION_FINISHED

10:53:37.980|CUMULATIVE_PROFILING_BEGIN

10:53:37.980|CUMULATIVE_PROFILING|SOQL operations|

Trigger.LeadConvert2: line 9, column 1: [Select a.Id, a.Name, a.Description From Account a Where a.Id = :Trigger.new[0].ConvertedAccountId]: executed 1 time in 5 ms

Class.LeadConvert2.TestLeadConvert2: line 11, column 1: [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1]: executed 1 time in 2 ms

 

10:53:37.980|CUMULATIVE_PROFILING|No profiling information for SOSL operations

10:53:37.980|CUMULATIVE_PROFILING|DML operations|

Class.LeadConvert2.TestLeadConvert2: line 13, column 1: Database.convertLead(Database.LeadConvert): executed 1 time in 383 ms

Class.LeadConvert2.TestLeadConvert2: line 6, column 1: Insert: SOBJECT:Lead: executed 1 time in 159 ms

Trigger.LeadConvert2: line 12, column 1: Update: SOBJECT:Account: executed 1 time in 8 ms

 

10:53:37.980|CUMULATIVE_PROFILING|method invocations|

External entry point: static testMethod void TestLeadConvert2(): executed 1 time in 546 ms

External entry point: public void invoke(): executed 1 time in 13 ms

Trigger.LeadConvert2: line 3, column 1: global Integer size(): executed 1 time in 0 ms

Class.LeadConvert2.TestLeadConvert2: line 10, column 1: global public void setDoNotCreateOpportunity(Boolean): executed 1 time in 0 ms

 

10:53:37.980|CUMULATIVE_PROFILING_END

LAMCORPLAMCORP

Thanks for your help so far. Sorry to keep bombarding you :)

imranrazaimranraza

Hi,

     For this line a.OwnerId = Trigger.new[0].Sales_ME1__c;

you need to specify ld.Sales_ME1__c = UserInfo.getUserId();

use this line in Test code and try.

Thanks

LAMCORPLAMCORP

Thanks Imran.. great help!!

 

I actually took out this line as it wasn't essential.

 

I also fixed the errors by prepopulating the Lead fields which I didn't do before.

 

The finished article which is now achieving 100% :)..looks like:

 

@isTest
Private Class LeadConvert2{
static TestMethod void TestLeadConvert2(){

    Lead ld = new Lead(Company = 'TestCompany', 
    LastName = 'Test', 
    OwnerId = '00530000004WakH',
    
    Sales_ME1__c = '00530000004WakH',
    Sales_ME2__c= '00530000005dI0c',
    Sales_DTR__c = System.Today(),
    Sales_CU__c = System.Today(),
    Sales_Project_Completion_Date__c = System.Today(),
    Sales_Division__c = 'Util-Eyes',
    Sales_Utility__c = 'Gas',
    Sales_Acquisition__c = 'Acquisition', 
    Sales_Next_Action_Comments__c = 'Test Next Action Text',
    Sales_Notes__c = 'Test Notes Text',
    
    CR_ME1__c = '00530000004WakH',
    CR_ME2__c = '00530000005dI0c',
    CR_DTR__c = System.Today(),
    CR_CU__c = System.Today()
    );
    insert ld;

    Database.LeadConvert lc = new database.LeadConvert();
    lc.setLeadId(ld.id);
    lc.doNotCreateOpportunity=true;
    LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
    lc.setConvertedStatus(convertStatus.MasterLabel);
    Database.LeadConvertResult lcr = Database.convertLead(lc);

    Account accts = new Account(
    Name = 'TestCompany',
    OwnerId = '00530000004WakH' );
    insert accts;
    
    Line_del__c salesLine = new Line_del__c(
    Name = 'Test insert new Monitor Line',
    // FF Sales Team 
    Team_s_Dept_s_del__c = 'a0P300000053ps9', 
    ME1__c = '00530000004WakH',
    ME2__c = '00530000005dI0c',  
    DTR3__c = System.Today(),
    CU__c = System.Today(),
    Project_Completion_Date__c = System.Today(),
    Division__c = 'Util-Eyes',
    Utility__c = 'Gas',
    Renewal_Acquisition__c = 'Acquisition', 
    Next_Action_Comments__c = 'Test Next Action Text',
    Notes__c = 'Test Notes Text',
    Linked_Account__c = accts.Id
    );

    Line_del__c CRLine = new Line_del__c (
    Name = 'Test insert new Monitor Line', 
    // CR Team 
    Team_s_Dept_s_del__c = 'a0P300000053prk', 
    ME1__c = '00530000004WakH', 
    ME2__c = '00530000005dI0c',      
    DTR3__c = System.Today(),
    CU__c = System.Today(),
    Next_Action_Comments__c = 'Test Next Action Text',
    Notes__c = 'Test Notes Text',
    Linked_Account__c = accts.Id   
    );
        
    test.StartTest();
    insert salesLine;
    insert CRLine;
    test.StopTest();
    
    }    
}
This was selected as the best answer