function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
LAMCORPLAMCORP 

Test Coverage for Lead Convert -Database.LeadConvertResult lcr = Database.convertLead(lc);

Hi all,

 

I am having a bit of bother. Hoping someone that has come across this can help.

 

I used to have a lead convert trigger and test class that worked fine.

 

Because of the usual (adding required fields) my test class needs updating.

 

It passes in Sandbox without any problems but I get an error when validating in production.

 

The error is:

LeadConvert2.TestLeadConvert2()Class711

Failure Message: "System.DmlException: ConvertLead failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, System.DmlException: Update failed. First exception on row 0 with id 00Qa0000014MjCuEAK; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, LeadConvert2: execution of AfterUpdate caused by: System.DmlException: I...

 

 

Line 71 is " Database.LeadConvertResult lcr = Database.convertLead(lc);  "

 

Can anyone help?

 

 

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

    Lead ld = new Lead(
    Company = 'TestCompany',
    OwnerId = '00530000005dI0c',
    LastName = 'Test',
    Phone = '07856656565',
    Email = 'test@test.com',
    Preferred_to_be_contacted_by__c = 'Email Only',
    Util_Eyes__c = True,
    LeadSource = 'Other',
    Linked_Basket__c  = '00130000015Cxwt',     
    Linked_Affiliate_1__c = 'a0N30000005aRCu',
    Aff_1_Profit_Share__c = 0,
    ME_rep_that_nurtured_this_lead__c = '00530000004WakH',
    industry = 'Finance',
    Initial_Email_Sent__c = True,
    Elec_AQ_Guestimation__c = 1000000000,
    Relationship_Status_New__c = 'Green [All good]',
    Client_Potential__c = 'Diamond [More than 100k]',
   
    Sales_Team__c = 'a0P300000053ps9',
    Sales_ME1__c = '00530000004WakH',
    Sales_ME2__c= '00530000005dI0c',
    Sales_DTR__c = System.Today(),
    Sales_Division__c = 'Util-Eyes',
    Sales_Utility__c = 'Gas',
    Sales_Acquisition__c = 'Acquisition',

    CR_ME1__c = '00530000004WakH',
    CR_ME2__c = '00530000005dI0c',
    CR_DTR__c = System.Today()
    );
    insert ld;
    
    Database.LeadConvert lc = new database.LeadConvert();
    lc.setLeadId(ld.id);
    lc.setDoNotCreateOpportunity(true);
    lc.setOverwriteLeadSource(false);
    lc.setSendNotificationEmail(false);
    LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
    lc.setConvertedStatus(convertStatus.MasterLabel);
    Database.LeadConvertResult lcr = Database.convertLead(lc);
    System.assert(lcr.isSuccess());
    system.debug('leadconvert'+lcr.isSuccess());
    system.debug('errors=' + lcr.getErrors());

    Account accts = new Account(
    Name = 'TestCompany',
    OwnerId = '00530000004WakH',
    ParentId = '00130000015Cxwt',
    Team_s_Dept_s__c = 'a0P300000053ps9',
    ME1__c = '00530000004WakH',
    ME2__c = '00530000005dI0c',
    Account_Status__c = 'Live',
    Local_Network_Folder__c = 'Test',
    Relationship_Status__c = 'Green [All good]',
    Client_Potential__c = 'Diamond [More than 100k]',
    Linked_Affiliate_1__c = 'a0N30000005aRCu',
    Aff_1_Profit_Split__c = 0
    );
    insert accts;
                
    //insert a Contact
    Contact con1 = new Contact (
    AccountId = accts.Id,
    FirstName = 'Contact',
    LastName = 'One',
    Email = 'contact1@test.com',
    Phone = '08445715544',
    MobilePhone = '07966565985',
    Title = 'Manager'
    );
    insert con1;
    
    Line_del__c salesLine = new Line_del__c(
    Name = 'Test insert new Monitor Line',
    Team_s_Dept_s_del__c = 'a0P300000053ps9',
    ME1__c = '00530000004WakH',
    ME2__c = '00530000005dI0c',  
    DTR3__c = System.Today(),
    Stage__c ='Closed Off',
    Division__c = 'Util-Eyes',
    Utility__c = 'Gas',
    Renewal_Acquisition__c = 'Acquisition',
    Linked_Account__c = accts.Id
    );

    Line_del__c CRLine = new Line_del__c (
    Name = 'Test insert new Monitor Line',
    Team_s_Dept_s_del__c = 'a0P300000053prk',
    ME1__c = '00530000004WakH',
    ME2__c = '00530000005dI0c',      
    DTR3__c = System.Today(),
    Stage__c ='Closed Off',
    Division__c = 'Dept',
    Utility__c = 'n/a',
    Renewal_Acquisition__c = 'n/a',
    Linked_Account__c = accts.Id   
    );
        
    test.StartTest();
    insert salesLine;
    insert CRLine;
    test.StopTest();
    
    }    
}

Best Answer chosen by Admin (Salesforce Developers) 
AmitSahuAmitSahu
Can you post the trigger code ? It seems to be coming from a trigger...The trigger could be on Lead object.,

All Answers

AmitSahuAmitSahu
Can you post the trigger code ? It seems to be coming from a trigger...The trigger could be on Lead object.,
This was selected as the best answer
LAMCORPLAMCORP

It was the trigger. Spent hours looging at the class!! I'm sure we have all been there before haha.

 

Thanks for the nudge.

LAMCORPLAMCORP
Referencing the wrong hard corded ID!!!!
Time to get more familiar with SOQL!