Skip to main content
3 of 3
replaced http://salesforce.stackexchange.com/ with https://salesforce.stackexchange.com/

convertStatus is null. My guess is that you have more than one valid converted status. You didn't get the appropriate error because you used a try-catch block to catch the QueryException without actually reporting an error. Consider changing your code from this:

try{
    convertStatus = [SELECT Id, MasterLabel 
                            FROM LeadStatus 
                            WHERE IsConverted=true and MasterLabel='Converted' and Id != null]; 
}catch(System.QueryException e){
    System.debug('caught ya!');
}

To this:

convertStatus = [SELECT Id, MasterLabel 
                            FROM LeadStatus 
                            WHERE IsConverted=true and MasterLabel='Converted' LIMIT 1]; 

In general, if you're not prepared to handle an exception, do not use a try-catch block. See this question and answer for when using try-catch is okay, and when it's not.

sfdcfox
  • 501.7k
  • 21
  • 473
  • 828