gs650x
gs650x

Reputation: 405

Trigger is running even if I create a new lead

As per the below code, this meant to update the first and last name only if I update a new lead but it is updating the first and last name of new lead as well Can someone please suggest. Thank you!

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

Upvotes: 1

Views: 350

Answers (2)

Raju Mahapatra
Raju Mahapatra

Reputation: 1

I have observed the same. Whenever a lead is inserted, the insert as well as the update triggers are called in lightning. But, in classic, it behaves as expected. While inserting a lead only insert trigger gets executed.

Upvotes: 0

Gareth Jordan
Gareth Jordan

Reputation: 976

Do you have a workflow or process builder field update action on the lead object? If so it would trigger an update on the record that was newly inserted thus would fire the trigger.

So in lightning there is s default Lead assignment rule that is active, if you disable it, the update doesn't happen. But it is weird that the rule causes an update in Lightning but not in classic, so that might still be a bug that should be reported to Salesforce.

Upvotes: 0

Related Questions