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
Srinivasa Amarendra Reddy VakaSrinivasa Amarendra Reddy Vaka 

before trigger is updating even for create new record

Hi All,

I am new to Salesforce and I just wrote my first Hello World Trigger on Lead object as below.

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

Guess what, this thing is running even when I create new Lead and setting the first and last names to hello world. What am I doing wrong?

- Amar
Nayana KNayana K
Is there any other triggers or workflows active?

 
Srinivasa Amarendra Reddy VakaSrinivasa Amarendra Reddy Vaka
There are no other triggers and workflows active. This is my first trigger and if I delete this trigger and create a Lead record, then the first name and the last name I keyed in stays, but with this trigger the new lead record's first name and last name is being created as Hello World.
Gurjit Singh 22Gurjit Singh 22
@Srinivasa 
Did you get the answer to this question, I am also struggling to understand the reason for new record updating 
Complete noviceComplete novice
Yup, I'm having the exact same issue.  I'm trying to follow the Apex Academy video and have created a brand new developer org (Lightning UI) and this code changes the lead name on insert.
Complete noviceComplete novice
Interestingly I have gone to an old Sandbox which is still in Classic and it works fine.  I'm going to continue the training in Classic but it would be good to know why it doesn't work properly in Lightning?
pragyanshu kukretipragyanshu kukreti
Hi, I am new to salesforce and was going through video lessons when i encountered my first trigger but I am unable to understand how this works as Lead field does not contain Firstname and Last name fields. Also, when i checked the fields in Build>Leads>Field section i can see First Name (with space) and Last Name( with space) undere Salutation field. then how come salesforce is updating name field when the trigger says l.FirstName = 'this'; Please help me understand as i have aready spent 2 hours searching for above details :(
Chaitanya nandulaChaitanya nandula
ObjectManager>Leads>Triggers>Hello world trigger>Click edit in the dropdown>Uncheck IsActive>save
User-added image

Please choose this as the best answer if it helps.
Michael Johnson 145Michael Johnson 145
This still doesn't work correctly, even in September 2021. No one seems to know what's going on.