+ Start a Discussion
ifthikar Ahmed 1ifthikar Ahmed 1 

clarification on Triggers


Additionally, if you update or delete a record in its before trigger, or delete a record in its after trigger, you will receive a runtime error. This includes both direct and indirect operations. For example, if you update account A, and the before update trigger of account A inserts contact B, and the after insert trigger of contact B queries for account A and updates it using the DML update statement or database method, then you are indirectly updating account A in its before trigger, and you will receive a runtime error.

can some one help me understan with an example pls
Best Answer chosen by ifthikar Ahmed 1
Raghu NaniRaghu Nani
Hi, ALl the bese for preparation.
 
The above explanation is while we performing Create/Update/Delete operation on record, we have to carefully enough our triggers logics should not suppost to to any Update/Delete operation on same record.
And while we performing Create/Update/Delete operation on record, if trigger on same object tries to modify the other records on same, the possibility of firing the same trigger again and again, it might causes the infinity.

Regards,
Raghu

All Answers

Raghu NaniRaghu Nani
I understood the what your doing with triggers, Can you explain the business use case, so we can change the design.

Regards,
Raghu
ifthikar Ahmed 1ifthikar Ahmed 1
@RaghHI Raghu, i am new to salesforce and preparing for PD1 certification, in trigger documentation i fond the below sentene and i am not able to get it 

Triggers can also modify other records of the same type as the records that initially fired the trigger. For example, if a trigger fires after an update of contact A, the trigger can also modify contacts B, C, and D. Because triggers can cause other records to change, and because these changes can, in turn, fire more triggers, the Apex runtime engine considers all such operations a single unit of work and sets limits on the number of operations that can be performed to prevent infinite recursion. See Execution Governors and Limits.
Additionally, if you update or delete a record in its before trigger, or delete a record in its after trigger, you will receive a runtime error. This includes both direct and indirect operations. For example, if you update account A, and the before update trigger of account A inserts contact B, and the after insert trigger of contact B queries for account A and updates it using the DML update statement or database method, then you are indirectly updating account A in its before trigger, and you will receive a runtime error
."
Raghu NaniRaghu Nani
Hi, ALl the bese for preparation.
 
The above explanation is while we performing Create/Update/Delete operation on record, we have to carefully enough our triggers logics should not suppost to to any Update/Delete operation on same record.
And while we performing Create/Update/Delete operation on record, if trigger on same object tries to modify the other records on same, the possibility of firing the same trigger again and again, it might causes the infinity.

Regards,
Raghu
This was selected as the best answer