You need to sign in to do that
Don't have an account?
Gurjit Singh 22
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';
}
}
trigger HelloWorld on Lead (before update) {
for(Lead l : Trigger.new){
l.FirstName = 'Hello';
l.LastName = 'World';
}
}
try this it should work , I think it is just because of trigger context variable. Apart from that everything looks fine.
link:: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_context_variables.htm
Please also check if there is no workflow, process builder etc. running at the time of lead creation and calling updates on the lead. Thanks.
HI all,
Thank you so much for responding, I have created a new org and after that, the first thing I did was created this trigger so there are no workflows and nothing from process builder or visual workflow and moreover this works fine in salesforce classic but in lightening it changes the name even for the new record
Can you confirm while creating a new lead the following optional is unchecked as shown in the screen shot below. It is
it is blurry, but it is this
Can you also share your Lead Settings?
Hi,
Thank you so for responding.
The problem is with the lightning only and I am not able to find any of such option in lightening, could you please suggest any other way
Yes sure Adbdul,
Please find below the logs and let me know if this can do.
42.0 APEX_CODE,FINEST;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WAVE,INFO;WORKFLOW,INFO
19:42:20.0 (415627)|USER_INFO|[EXTERNAL]|0057F000003arvb|gs650d@gmail.com|Pacific Standard Time|GMT-07:00
19:42:20.0 (456132)|EXECUTION_STARTED
19:42:20.0 (458684)|CODE_UNIT_STARTED|[EXTERNAL]|Workflow:Lead
19:42:20.0 (8784633)|WF_RULE_EVAL_BEGIN|Assignment
19:42:20.0 (8813154)|WF_SPOOL_ACTION_BEGIN|Assignment
19:42:20.0 (8828481)|WF_ACTION|.
19:42:20.0 (8835476)|WF_RULE_EVAL_END
19:42:20.0 (8941324)|WF_ACTIONS_END| None
19:42:20.0 (8952835)|CODE_UNIT_FINISHED|Workflow:Lead
19:42:20.0 (8960517)|EXECUTION_FINISHED
19:42:20.72 (72631441)|USER_INFO|[EXTERNAL]|0057F000003arvb|gs650d@gmail.com|Pacific Standard Time|GMT-07:00
19:42:20.72 (72653754)|EXECUTION_STARTED
19:42:20.72 (72658467)|CODE_UNIT_STARTED|[EXTERNAL]|TRIGGERS
19:42:20.72 (73405756)|CODE_UNIT_STARTED|[EXTERNAL]|01q7F000001J6HQ|leadtest on Lead trigger event BeforeUpdate
19:42:20.72 (73467027)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8
19:42:20.72 (73507287)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8
19:42:20.72 (73930634)|HEAP_ALLOCATE|[72]|Bytes:3
19:42:20.72 (74002406)|HEAP_ALLOCATE|[77]|Bytes:152
19:42:20.72 (74018757)|HEAP_ALLOCATE|[342]|Bytes:408
19:42:20.72 (74030991)|HEAP_ALLOCATE|[355]|Bytes:408
19:42:20.72 (74042603)|HEAP_ALLOCATE|[467]|Bytes:48
19:42:20.72 (74073502)|HEAP_ALLOCATE|[139]|Bytes:6
19:42:20.72 (74190116)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8
19:42:20.72 (74223129)|VARIABLE_SCOPE_BEGIN|[1]|this|leadtest|true|false
19:42:20.72 (74488596)|VARIABLE_ASSIGNMENT|[1]|this|{}|0x1da6cb42
19:42:20.72 (74559299)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8
19:42:20.72 (74579163)|VARIABLE_SCOPE_BEGIN|[1]|this|leadtest|true|false
19:42:20.72 (74597263)|VARIABLE_ASSIGNMENT|[1]|this|{}|0x1da6cb42
19:42:20.72 (74606169)|STATEMENT_EXECUTE|[1]
19:42:20.72 (74609012)|STATEMENT_EXECUTE|[2]
19:42:20.72 (74653927)|HEAP_ALLOCATE|[2]|Bytes:4
19:42:20.72 (74761641)|HEAP_ALLOCATE|[50]|Bytes:5
19:42:20.72 (74788071)|HEAP_ALLOCATE|[56]|Bytes:5
19:42:20.72 (74798050)|HEAP_ALLOCATE|[64]|Bytes:7
19:42:20.72 (74832054)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:4
19:42:20.72 (74847402)|VARIABLE_ASSIGNMENT|[2]|this.le|[]|0x1da6cb42
19:42:20.72 (74868919)|STATEMENT_EXECUTE|[4]
19:42:20.72 (75057520)|HEAP_ALLOCATE|[4]|Bytes:5
19:42:20.72 (75119704)|HEAP_ALLOCATE|[4]|Bytes:4
19:42:20.72 (75133766)|VARIABLE_SCOPE_BEGIN|[4]|l|Lead|true|false
19:42:20.72 (75682323)|VARIABLE_ASSIGNMENT|[4]|l|{"Status":"Open - Not Contacted","LastModifiedDate":"2018-05-23T02:42:20.000Z","Company":"FIS","IsDeleted":false,"DoNotCall":false,"IsConverted":false,"FirstName":"Abdul","IsUnreadByOwner":false,"HasOptedOutOfEmail":false,"HasOptedOutOfFax":false,"SystemModstamp":"2018-05-23T02:42:20.000Z","CleanStatus":"Pending","CreatedById":"0057F000003arvbQAA","CreatedByID":"0057F000003arvbQAA","OwnerId":"0057F000003arvbQAA","CreatedDate":"2018-05-23T02:42:20.000Z","Id":"00Q7F00000A8qwTUAR","LastName":"Khatri","LastModifiedByID":"0057F000003arvbQAA","LastModifiedById":"0057F000003arvbQAA","LastTransferDate":"2018-05-23T02:42:20.000Z"}|0x508dfec7
19:42:20.72 (75703046)|STATEMENT_EXECUTE|[5]
19:42:20.72 (75705670)|STATEMENT_EXECUTE|[6]
19:42:20.72 (75710045)|HEAP_ALLOCATE|[6]|Bytes:5
19:42:20.72 (75948542)|VARIABLE_ASSIGNMENT|[6]|this.FirstName|"Hello"|0x508dfec7
19:42:20.72 (75957571)|STATEMENT_EXECUTE|[8]
19:42:20.72 (75961552)|HEAP_ALLOCATE|[8]|Bytes:5
19:42:20.72 (76194306)|VARIABLE_ASSIGNMENT|[8]|this.LastName|"world"|0x508dfec7
19:42:20.72 (76203920)|STATEMENT_EXECUTE|[10]
19:42:20.72 (76255318)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:4
19:42:20.72 (76277369)|HEAP_ALLOCATE|[4]|Bytes:5
19:42:20.72 (76293361)|VARIABLE_ASSIGNMENT|[4]|l|null|
19:42:20.76 (76303674)|CUMULATIVE_LIMIT_USAGE
19:42:20.76 (76303674)|LIMIT_USAGE_FOR_NS|(default)|
Number of SOQL queries: 0 out of 100
Number of query rows: 0 out of 50000
Number of SOSL queries: 0 out of 20
Number of DML statements: 0 out of 150
Number of DML rows: 0 out of 10000
Maximum CPU time: 0 out of 10000
Maximum heap size: 0 out of 6000000
Number of callouts: 0 out of 100
Number of Email Invocations: 0 out of 10
Number of future calls: 0 out of 50
Number of queueable jobs added to the queue: 0 out of 50
Number of Mobile Apex push calls: 0 out of 10
19:42:20.76 (76303674)|CUMULATIVE_LIMIT_USAGE_END
19:42:20.72 (77879907)|CODE_UNIT_FINISHED|leadtest on Lead trigger event BeforeUpdate
19:42:20.72 (88407067)|CODE_UNIT_STARTED|[EXTERNAL]|Workflow:Lead
19:42:20.72 (91661572)|WF_RULE_EVAL_BEGIN|Assignment
19:42:20.72 (91675421)|WF_SPOOL_ACTION_BEGIN|Assignment
19:42:20.72 (91686551)|WF_ACTION|.
19:42:20.72 (91692903)|WF_RULE_EVAL_END
19:42:20.72 (91776152)|WF_ACTIONS_END| None
19:42:20.72 (91787234)|CODE_UNIT_FINISHED|Workflow:Lead
19:42:20.72 (149258381)|CODE_UNIT_FINISHED|TRIGGERS
19:42:20.72 (149278147)|EXECUTION_FINISHED
Please find below the workflow screenshot.