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
}
}
}