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
Kumar SarathyKumar Sarathy 

My Update Trigger also fires during Create in Lightning. Works fine in Classic.

I created a very basic Trigger:

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

When I create a new Lead record in Classic, it works as expected (ie, no change since it should fire only in Update) but when I create a new Lead record in Lightning, as soon as I save, the first and last name gets updated to Hello World.

This is a brand new developer Org and so there are no other triggers etc. Has anyone else run into this problem?
GhanshyamChoudhariGhanshyamChoudhari
Hi Kumar ,
I have absolutely no idea why it is behaving like this.
Please raise a case to salesforce support. They will help you

 
Amit Chaudhary 8Amit Chaudhary 8
Hi Kumar,
Please in your org you have any Process builder or workflow on Lead object. May be that was executing on insert as well ?
GhanshyamChoudhariGhanshyamChoudhari
Hi Amit,
I tried above code I am also facing the same issue.
Above code is working fine in classic but not in lightning. (if there is any PB or workflow on lead then it will not work in classic also). 
I checked debug log while creating a record in the lightning, the trigger is firing on before insert.
 
Kumar SarathyKumar Sarathy
Amit, 
This is a brand new Developer Org. So there is absolutely no other triggers, Workflow, or Process Builder running. 
Kumar SarathyKumar Sarathy
Thanks, Ghanshyam. I will report to Salesforce and will update here with their response.
 
Vijay AdusumilliVijay Adusumilli
I tried this using Anymous window. The update trigger is not being called. However, if you use the Sales App and add a new lead, this trigger is being called. There is a workflow that is triggering update on Lead. I could not see that workflow in my environment and that workflow is somehow doing more work when you insert a Lead using the Sales Application (Lightning) and not when using Anonymous Window.
Eric JJ van HorssenEric JJ van Horssen

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.

Peter Wouda 17Peter Wouda 17
This very same lead trigger gets fired when clicking on a Lead in a lead list view in LEX. When you end up on the LEX detail, the first/last name is updated to Hello and World. Does anyone recognize this and/or know who to prevent it?

Clean org, developer edition, summer'19.
Eric JJ van HorssenEric JJ van Horssen

@Peter Wouda, I can narrow it down a little bit for you. Only just realised this, had not realised it when I previously run into this issue.

I have just tested this, and initially I did not see your issue. But I quickly was able to reproduce it, under the right conditions.

The scenario you describe, from a List View in Lightning, will happen, if you are the owner, and you had not read the Lead yet. In general opening the Lead, will mark the Lead as Read.

It seems in Classic, this update, does not cause the update trigger to fire, but it does in Lightning.

I created a Lead through the API (Dev Console) with an owner, who was not the currently logged in user. Viewing the Lead, either by opening the detail page from the dev console, or from a list view, did not change anything.

Logging in as the user who is the owner, and then refresh the tab, in which I still had the Lead open, loads that tab, with the other user, if that user is the owner, the Lead gets updated.

Now testing this by looking at 'IsUnreadByOwner' in my trigger to see what the value is for trigger.old and trigger.new, I do get false for both values, eventhough it was true, just before I viewed it. So I do not know how to test securely on this.
Still the test I performed, all point to unread by owner, from my point of view.

In a way I wonder whether we should try and open a case for this, even though teh article states that it is by design, it does not clarify this well, and it in my opinion, if true, should not just be an article, but become part of the developer documentation.

Peter Wouda 17Peter Wouda 17
Hi Eric,

Thanks you so much for your analysis. I tested your hypothesis:
  • Clicked on a lead I own in a list view, noticed first/last name to be updated
  • Deactivated trigger
  • Edited first/last name of lead to "Test Trigger"
  • Reactivated trigger
  • Clicked again on lead from same list view
  • Found no update on first/last name
So yes, it sounds like that "Unread" flag plays an undesired role in the order of events. I think I'll log a case to let SF take a look. It should not have an effect on well written (idempotent) triggers, but the world is not that ideal.


 
Eric JJ van HorssenEric JJ van Horssen
Happy to help get you in the right direction. Hopefully Salesforce will take resonsibility for this strange behaviour.