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
Lee Kraus MtnPtLee Kraus MtnPt 

Before Update Trigger firing on New record in Lightning

trigger HelloWorld on Lead (before update) {
    For (Lead l: Trigger.new) {
        l.FirstName = 'Hello';
        l.LastName = 'World';
        
    }

}
This Trigger works as expected in Classic, but will update a New record in Lightning.  Why?
 
Raj VakatiRaj Vakati
It's not firing when I tested in my instance. Can you please check on your Lead page, is there any custom component that will update the lead records?  I believe that might be an issue 

 
{!pramod_nishane}{!pramod_nishane}
Hi Lee,

A typical reason for this is that you have Lead Assignment rules. Once those execute, a new owner is assigned and hence the Lead object is updated.
you can see the same under "Standard" Lead Assignment Rule which is Active by default in Org.
where the second rule is  "Lead: CountryNOT EQUAL TOUS,USA,United States,United States of America".
This assignment rule is firing your before update trigger "HelloWorld" and changing the FirstName and LastName to Hello Word respectively.

If you want to cross check that above assignment rule is executing and updating newly created lead record or not then do following:-
1) Assign another available user (not yours)from your Org under "Step 3: Select the user or queue to assign the Lead to".
2) Save the assignment rule.
3) Try inserting new Lead from your login.
4) Keep Country field blank and save record.

Basically you are creating lead so owner of lead should be yourself but in this case owner of newly created lead is not you.
Meaning that lead assignment rule is executing when you creatimg new lead and because of that before update trigger is executing and changing the FirstName and LastName of lead.

Let me know in case of any concerns.

Please mark this answer as the solution/ best answer if it solves your purpose so that it can help other community members.

Thanks,
Pramod Nishane
Salesforce Consultant
Varasi LLC
www.varasi.com
Lee Kraus MtnPtLee Kraus MtnPt
@Pramod Should disabling this Standard Lead Assignment Rule keep it from firing?  Thank you for your reply!
{!pramod_nishane}{!pramod_nishane}
Hi Lee,

Though disabling Standard Lead assignment rule before update trigger is still firing in Lightning.
i am also surprised with the behaviour but i am still checking for what's happening in background and invoking trigger.

Meanwhile can you raised Case with salesforce?
Please update on forum if you found solution for this problem so that all will get good idea for such wierd behaviour.

Thanks,
Pramod Nishane
Salesforce Consultant
Varasi LLC
www.varasi.com
Lee Kraus MtnPtLee Kraus MtnPt
Yes, I can raise a case. Thank you!