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
Lavanya Ponniah 3Lavanya Ponniah 3 

This is my trigger it shows

trigger LeadConvert on Lead (before update)
{
    for(Lead l : Trigger.New)
    {
    
     if (trigger.old[0].isConverted == false && trigger.new[0].isConverted == true)
     {    
         if (Trigger.new[0].ConvertedContactId != null)
         {
    Contact contCk = [Select Id, Name From Contact Where Id =: l.ConvertedContactId];
             contCk.LastName = l.Name;
             update contCk;
         }
            if (Trigger.new[1].ConvertedContactId != null)
         {
    Contact contCk = [Select Id, Name From Contact Where Id =: l.ConvertedContactId];
             contCk.LastName = l.Name;
             update contCk;
         }
            if (Trigger.new[2].ConvertedContactId != null)
         {
    Contact contCk = [Select Id, Name From Contact Where Id =: l.ConvertedContactId];
             contCk.LastName = l.Name;
             update contCk;
         }
            if (Trigger.new[3].ConvertedContactId != null)
         {
    Contact contCk = [Select Id, Name From Contact Where Id =: l.ConvertedContactId];
             contCk.LastName = l.Name;
             update contCk;
         }
            if (Trigger.new[4].ConvertedContactId != null)
         {
    Contact contCk = [Select Id, Name From Contact Where Id =: l.ConvertedContactId];
             contCk.LastName = l.Name;
             update contCk;
         }
         if (Trigger.new[0].ConvertedAccountId != null)
         {
             Account accCk = [Select Id, Name From Account Where Id =: l.ConvertedAccountId];
             accCk.Name = l.Name;
             update accCk;               
         }
         if (Trigger.new[0].ConvertedOpportunityId != null)
         {
          Opportunity oppCk = [Select Id, Name From Opportunity Where Id =: l.ConvertedOpportunityId];
             oppCk.Name = l.Name;
             update oppCk;
         }
     }
}
}
This shows 
Error: System.DmlException: Update failed. First exception on row 0 with id 00Q9000000TNp8GEAT; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, LeadConvert: execution of BeforeUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 003900000158pD8AAI; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Last Name]: [Last Name] Trigger.LeadConvert: line 12, column 1: [] (System Code)
Ankit AroraAnkit Arora
Check using debug that in this line "contCk.LastName = l.Name;"  l.Name is not blank? Also there are so many flaws in code, like you've query in for loop, why not using l.lastName to fill contact's last name etc..
SravsSravs
Hi Lavanya, 

It looks like the last name of converted contact is gettng null. This could happen in another trigget. Please check in debug logs to identify where it getting nullified. 

Regards,
Sravs 
bob_buzzardbob_buzzard
Your trigger doesn't look right to me - you iterate every record in trigger.new and carry out the same processing for records one through four in the list each time through the loop.  

That said, line 12 is the first time that you try to update a contact.  The fact that the LastName required field is missing implies that l.name is null, though I can't see how that would happen unless that somehow gets blanked for a converted lead.  I'd try putting some debug into the trigger to output the exacts state of the contact, for example:
if (Trigger.new[0].ConvertedContactId != null)
{
    Contact contCk = [Select Id, Name From Contact Where Id =: l.ConvertedContactId];
    contCk.LastName = l.Name;
    System.debug('### Contact to update = ' + contCk);
    update contCk;
}