[SalesForce] Lead before update runs on insert

I have a fresh dev org, with nothing at all in it other than this one trigger that is below. When I create a new lead, this trigger is ran. (ie, I put the new leads name as John Smith and Company as ABC Co). When I click save, the record shows with hello world as the first and last name on the new lead. I do not understand what would cause the before update trigger to run on insert. This only happens in lightning, not in classic. I am in Version 41.0 but also tried it in 40.0 and 34.0 and I get the same results. Any insight would be greatly appreciated. Thank you (if this is a dupe, sorry…I could not find an answer to this).

trigger LeadTrig on Lead (before update) {
    for(Lead l : trigger.new){
        l.firstName = 'hello';
        l.lastName = 'world';
    }
}

Best Answer

Lead update apex trigger fires on new lead creation in Lightning Experience https://help.salesforce.com/articleView?id=000271134&language=en_US&type=1

Salesforce currently has this documented as working by design.

Lead update apex trigger fires on new lead creation in Lightning Experience
Knowledge Article Number    000271134
Description 

In Lightning Experience, Lead update apex trigger fires on new lead creation from UI. This behavior is not observed in Classic.

This scenario can be reproduced by following the below steps.       
Create an apex trigger on Lead  (Sample shown below)                  
                                 trigger testleadupdateLEX on Lead (before update) {
                                 System.debug('before update');
                                  }
Set the debug logs to observe the behavior and create a new lead.
Observe Lead update trigger getting fired when a new lead is created  from Lightning Experience.

Note: Lead update trigger does not get fired when a new lead is created from Classic.




Resolution  

This is currently working as designed and this behavior is expected while creating a new lead in Lightning experience.The lead creation process is doing an implicit update behind the scenes causing the trigger to execute.
Related Topic