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
Steve BerleySteve Berley 

Test Class: How to force a lead conversion error?

I have a method that includes conversion of a lead.  The database.convertlead() call is wrapped in a try/catch.
try {
	Database.LeadConvertResult lcr = Database.convertLead(lc);
} catch (exception e) {
    lpTools.logError('Client_Hub_Attachment_Tools.convertPortalProspects', e);
}

How do I force an error in my test code so I can exercise the catch part?

Thanks,

Steve 

 
Gururaj BGururaj B
Disable the app permission, "Convert Leads" for the user profile that you are using to test. This will lead to error and catch block will be executed.
Amit Singh 1Amit Singh 1
Hi Steve, 
Replace the above code block with the below code block
try {
	Database.LeadConvertResult lcr = Database.convertLead(lc);
	if(Test.isRunningtest()))
		Integer i = 10/0;
} catch (exception e) {
    lpTools.logError('Client_Hub_Attachment_Tools.convertPortalProspects', e);
}