Loading

Error 'CANNOT_UPDATE_CONVERTED_LEAD' When Executing Apex Trigger on Lead Record

Udgivelsesdato: Aug 4, 2025
Beskrivelse

When an Apex Trigger runs on the Lead object in Salesforce, the following error may be thrown:

Error Message: CANNOT_UPDATE_CONVERTED_LEAD

This error occurs specifically when the trigger logic attempts to modify or update a Lead record that has already been converted, or when it tries to reference the Lead's record ID after conversion has taken place.

In Salesforce, Lead conversion is the process of converting a qualified Lead into an Account, Contact, and optionally an Opportunity. Once a Lead is converted, Salesforce treats the Lead record as read-only for most field updates. Any Apex Trigger logic that attempts to perform a DML update on a converted Lead will throw this error.

A common scenario where this occurs is an after-update or after-insert Apex Trigger on the Lead object that does not check whether the Lead is already converted before attempting further DML operations.

Løsning

This article explains how to resolve the CANNOT_UPDATE_CONVERTED_LEAD error in an Apex Trigger by filtering out converted Lead records before performing DML operations.

Once a Lead is converted, only the convertedAccountId or convertedContactId fields can be referenced on that Lead record. Any attempt to update other fields via an Apex Trigger will result in the CANNOT_UPDATE_CONVERTED_LEAD error.

To prevent this error, update the Apex Trigger logic to exclude converted Lead records before performing any DML operations. Use the IsConverted field on the Lead object to filter out converted records.

The following example shows how to add this check in an Apex Trigger:

trigger LeadTrigger on Lead (before update, after update) {
    List<Lead> unconvertedLeads = new List<Lead>();

    for (Lead l : Trigger.new) {
        if (!l.IsConverted) {
            unconvertedLeads.add(l);
        }
    }

    // Perform DML operations only on unconverted Leads
    if (!unconvertedLeads.isEmpty()) {
        // Add your trigger logic here
    }
}

By checking IsConverted before executing DML operations, the Apex Trigger only processes Lead records that have not yet been converted, which prevents the CANNOT_UPDATE_CONVERTED_LEAD error from being thrown.

 

 

Vidensartikelnummer

000384333

 
Indlæser
Salesforce Help | Article