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
HNT_NeoHNT_Neo 

Lead Trigger Causing First Name and Last Name to only be 20 characters max each

Hello, 

We have a Lead Trigger set in our org and its been active since 2013. 
 I came across this Salesforce document stating that the first name and last name character limits have increased. 

https://help.salesforce.com/articleView?id=leads_fields.htm&type=5

First Name character limit is 40
Last Name character limit is 80

So created a lead with 30 characters for the first name and 40 for the last name, to be modest. Well, I received the error message that the max limit is 20 characters, etc. Contacted Salesforce, and concluded that a custom lead trigger, shown below, was the culprit. I deactivated it, tested a new lead with the number of characters I tried before, and it worked. 

Unfortunately, I can't deactivate this trigger in production since it is executing various actions. Is there a way to modify this code to allow the first and last name to increase the character limits when a new lead is created? 

The past few months we've been receiving email erroring out and we found out why, but now need to know if anyone can help me out. 

Thanks!
 
trigger triggerLead on Lead (after insert, before insert, before update, after update) {

    LeadTrigger lt = new LeadTrigger();
    if (Trigger.isInsert)
        lt.LeadInsertion(Trigger.New, Trigger.isBefore, Trigger.isAfter);
    else if (Trigger.isBefore)
        lt.LeadUpdate(Trigger.New, Trigger.old, Trigger.isBefore);
    
    if (Trigger.isAfter) {
        lt.ReassignALOnClosedLeads(Trigger.New, Trigger.old, null);
        lt.AddToCampaign(Trigger.New, Trigger.oldMap);
        lt.ProcessQuotingLeads(Trigger.New, Trigger.old);
    } else 
        lt.PopulateAmbassador(Trigger.New, Trigger.old);   
        
    if (Trigger.isBefore && Trigger.isUpdate){
        lt.CreateLastVisitTask(Trigger.new);
        lt.CopyHistoryLog(Trigger.new, Trigger.oldMap);   
    }
}

 
Best Answer chosen by HNT_Neo
Abhishek BansalAbhishek Bansal
Hi,

Please increase the version of the trigger in the xml file and then the new limits will be applied to this existing trigger as well. Please follow the below steps:
1. Go to Apex Triggers from Setup
2. Click on your trigger
3. Click on the Edit button
4. Now switch the tab to Version settings and change the version to the latest one as available on the Production.
5. Please see the screenshot attached below for you reference:
User-added image

Please let me know if you need any further information on this.

Thanks,
Abhishek Bansal.

All Answers

Abhishek BansalAbhishek Bansal
Hi,

Please increase the version of the trigger in the xml file and then the new limits will be applied to this existing trigger as well. Please follow the below steps:
1. Go to Apex Triggers from Setup
2. Click on your trigger
3. Click on the Edit button
4. Now switch the tab to Version settings and change the version to the latest one as available on the Production.
5. Please see the screenshot attached below for you reference:
User-added image

Please let me know if you need any further information on this.

Thanks,
Abhishek Bansal.
This was selected as the best answer
HNT_NeoHNT_Neo
Thank You Abhishek! That did the trick. 

In our Org, not only did we have an old API version set, but once a lead was created, another class is creating a new record in another custom object. The other custom object had the character for first name set to 20 and last name set to 20 characters. I updated the character limits of those 2 fields and both the lead and custom object record were created flawlessly.