0

I am trying to deploy a class with a test that automatically converts leads. This Apex method will be invoked via Process Builder. It works fine in the Sandbox environment, and the test worked fine before the new year, but now it is failing when promoting as well as re-running in the Sandbox.

Looking through the debug logs, the exception occurs within the call to database.convertLead

10:50:32.455 (9455361693)|EXCEPTION_THROWN|[16]|System.DmlException: ConvertLead failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Validation error on Lead: Select an Individual record type.: []

I am using Financial Services Cloud, and the default record type "Individual" is there with no specific mappings, following https://developer.salesforce.com/docs/atlas.en-us.financial_services_cloud_object_reference.meta/financial_services_cloud_object_reference/fsc_api_mdt_individual_record_type_mapper.htm

And additional error upward on the log is: 10:50:32.277 (9372172718)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this|"common.apex.runtime.impl.ExecutionException"|0x2fa3e1f2 10:50:32.277 (9372214051)|VARIABLE_ASSIGNMENT|[EXTERNAL]|message|"Record Type does not (6 more) ..."

I would love to know what "6 more" refers to.

    @isTest(SeeAllData=true)
          public class TestAutoConvertLeads{
          static testMethod void createnewlead() {
          User userToCreate = [Select id from user where profile.name='System Administrator' AND isActive = true limit 1];
          Recordtype recordtypeid = [Select id from recordtype where developername = 'Referral' Limit 1];
          
          Test.startTest();    
          Lead leadToCreate =new Lead();
          List<id> Ids= New List<Id>();
          leadToCreate.ownerid= userToCreate.id;
          leadToCreate.LastName ='TestLead';
          leadToCreate.Company='TestLead';
          leadToCreate.LeadSource='Social Channels';
          leadToCreate.Rating='';
          leadToCreate.Status='';
          leadToCreate.recordtypeid= recordtypeid.id;
          insert leadToCreate; 
          
          Ids.add(leadToCreate.id);
          AutoConvertLeads.LeadAssign(Ids);
          
          Account[] newAccount = [Select id from Account WHERE LastName = 'TestLead'];
          System.assert(!newAccount.isEmpty());
    
          Test.stopTest();
       }
    }

    Public class AutoConvertLeads 
    {     @InvocableMethod   
        public static void LeadAssign(List<Id> LeadIds)  
        {         
            LeadStatus CLeadStatus= [SELECT Id, ApiName FROM LeadStatus WHERE IsConverted=true and ApiName = 'Closed' Limit 1];    
            List<Database.LeadConvert> MassLeadconvert = new List<Database.LeadConvert>();    
            for(id currentlead: LeadIds){                
                Database.LeadConvert Leadconvert = new Database.LeadConvert();    
                Leadconvert.setLeadId(currentlead);                               
                Leadconvert.setConvertedStatus(CLeadStatus.ApiName);             
                Leadconvert.setDoNotCreateOpportunity(FALSE);
                MassLeadconvert.add(Leadconvert);    
            }                  
            if (!MassLeadconvert.isEmpty())
            {            
                List<Database.LeadConvertResult> lcr = Database.convertLead(MassLeadconvert);       // fails here
            }    
        } 
    }
7
  • 1
    Have you checked if the user profile has assigned this record type? Individual on this case. Commented Feb 17, 2021 at 22:45
  • Good call, but yes, the user profile does indeed have the record type. Adding the example Lead created in the test.
    – Kyle J V
    Commented Feb 18, 2021 at 13:37
  • 1
    I'm confused, the test that creates the Lead assign the record type 'Referral'. Is that what you intended? I thought you wanted to use Individual (maybe that is part of FSC config). Btw: avoid seeAllData. Commented Feb 18, 2021 at 17:38
  • "Individual" is an Account record type, not Lead.
    – Kyle J V
    Commented Feb 18, 2021 at 17:50
  • 1
    I get you, no worries: could it be because of these changes: help.salesforce.com/… Commented Feb 18, 2021 at 22:58

1 Answer 1

0

After a support call with Salesforce Tier 2, they were able to determine that there was an added validation that the lead required a product defined and that the test would work if I also omitted the Company Name. It may have to do with the changes that Jeferson mentioned.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .