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
Mohammad Alazzouni 16Mohammad Alazzouni 16 

Flow not working after changing API name

We recently wrote a flow where when a certain field in a Lead (mk_fl_user_id__c) is populated, then the process builder will automatically convert that Lead into a Contact. We've used a comobination of a process builder to invoke the following APEX class:
 
public class AutoConvertLeads {
    @InvocableMethod
    public static void LeadAssign(List<Id> LeadIds)
    {
        LeadStatus CLeadStatus= [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true 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.MasterLabel);
                Leadconvert.setDoNotCreateOpportunity(TRUE); //Remove this line if you want to create an opportunity from Lead Conversion 
                MassLeadconvert.add(Leadconvert);
        }
        
        if (!MassLeadconvert.isEmpty()) {
            List<Database.LeadConvertResult> lcr = Database.convertLead(MassLeadconvert);
        }
    }
}
And this is the test class to push it to production
 
@isTest(seeAllData=false)
public class AutoConvertLeadsTest {

    public static Lead newLead;
    public static List<Id> leadIds;
    //public static String MK_fl_user_id; --ADD BACK IN
    public static String original_Source; //--DELETE
    
    //public AutoConvertLeads ACLClass;
    
    static void init(){
        leadIds = new List<Id>();
        //MK_fl_user_id = '1234';
        original_Source = 'test'; // --DELETE
        
        //Create a new Lead with MK_fl_user_id__c not Null
        // newLead = new Lead(MK_fl_user_id__c = MK_fl_user_id); --ADD BACK IN
        newLead = new Lead(Original_Source__c = original_Source); // --DELETE
        newlead.company = 'testLead';
        newlead.lastname = 'testOtherLead';
        insert newlead;
    }
    
    @isTest static void checkIfContactCreated(){
        init();
        Test.startTest();
        
        leadIds.add(newLead.Id);
        
        //Call Invokable Method
        AutoConvertLeads.LeadAssign(leadIds);
        
        Contact a;
        //Test that a contact was created.
        //a = [SELECT Id, MK_fl_user_id__c FROM Contact WHERE MK_fl_user_id__c = :MK_fl_user_id  LIMIT 1]; --ADD BACK IN
        a = [SELECT Id, Original_Source__c FROM Contact WHERE Original_Source__c = :original_Source  LIMIT 1]; // --DELETE
        
        //System.assertEquals(MK_fl_user_id, a.MK_fl_user_id__c); --ADD BACK IN
        System.assertEquals(original_Source, a.Original_Source__c); // --DELETE
        Test.stopTest();
    }
}

Everything was working perfectly fine, yesterday we were asked to change the API name from MK_fl_user_id__c to MKto71_fl_user_id__c for both the Lead and Contact Object.

After we did the changes, I double checked the mappings and double checked the process builder, everything seems to be in place. However, the flow is not working anymore!

I get the following error:

Error Occurred: An Apex error occurred: System.DmlException: ConvertLead failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, There was an error converting the lead. Please resolve the following error and try again: LH.LH_Contact: execution of AfterInsert caused by: System.SObjectException: Invalid field mk_fl_user_id__c for Contact (LH) : [] 

I am not sure where to start. Any advice would be highly appreciated.
Mohammad Alazzouni 16Mohammad Alazzouni 16
I would also like to note that mk_fl_user_id__c has been changed to MKto71_fl_user_id in both Contacts and Leads, I don't know why I am still getting the following error:

Please resolve the following error and try again: LH.LH_Contact: execution of AfterInsert caused by: System.SObjectException: Invalid field mk_fl_user_id__c for Contact (LH) : []