Execution of Trigger and Workflow – A practical Analysis

Target Record: A Case record with Status =”New” in Database. There is trigger which updates the value of Status =”Working” in before update event. There is workflow too which updates to Status to “Escalated”. So, we are going to analyze how system behaves in these scenarios: Lets play as below: P.S: In all events, old …

Execution of Trigger and Workflow – A practical Analysis Read More »

Apex Trigger Practice (4)

Prerequisites Standard Contact Object There is checkbox Field on Contact called “Active” A custom object “Employment Detail” as child object of Contact Object There is a picklist field “Status” having two values: Employee, Ex-Employee And a lookup field to Conatct Requirement: If Contact field “Active” is marked as true, then If no record of child …

Apex Trigger Practice (4) Read More »

PD2 Tough Questions – Refresh your amygdala

Integer x = 1; Integer Y = 0; While(x < 10){Y++;} Will go in infinite loop because x is not being updated inside loop to break the condition. Integer x = 1; Integer Y = 0;While(x < 10){Y++;} ______________________ Contact con = new Contact( LastName = ‘JOHNSON’, email = ‘Web@test.com’);Savepoint sp = Database.setSavepoint();insert con;Database.rollback(sp);system.debug(con);con.email = …

PD2 Tough Questions – Refresh your amygdala Read More »

Why Before Trigger should not have DML for other objects

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 …

Why Before Trigger should not have DML for other objects Read More »

Apex Trigger Practice (3) – Trigger on Attachments to count the number of attachments

Question Hints: Account is standard object and attachment is child object. Requirement: We need to create an Apex Trigger on Attachments to count the number of attachments on the object – let’s take Account – and store in number field “Number of attachments”. Trigger is considering all the possible scenarios in this – after insert, after …

Apex Trigger Practice (3) – Trigger on Attachments to count the number of attachments Read More »

Apex Trigger Practice (1) – Update Account Open Case Status

Question Hints: Account is parent object of Case. Case’s status field is categorized into two types – Open or closed which can be tracked by field “IsClosed”. Requirement: On Account, there is a checkbox field “Has Open Case”, if there is any open Case under account, this field should be checked. Please make sure all …

Apex Trigger Practice (1) – Update Account Open Case Status Read More »