LogoRazy
Salesforce Interview Guide: Triggers, LWC, and Best Practices
salesforceapexinterviewlwctriggers

Salesforce Interview Guide: Triggers, LWC, and Best Practices

Jan 28, 2026Abhishek Razy5 min read

Salesforce Development: Complete Interview and Implementation Guide

Photo by jplenio on Pixabay
Photo by jplenio on Pixabay

A comprehensive guide covering Apex triggers, Lightning Web Components, security models, and integration patterns for Salesforce developers and administrators.

Triggers and Apex Fundamentals

Order of Execution in a Trigger Context

When a record is inserted, Salesforce follows a specific sequence:

  1. System Validation Rules (required fields, field formats)

  2. Before Triggers (executes before record is saved)

  3. Custom Validation Rules (user-defined rules)

  4. After Triggers (executes after record is saved)

  5. Assignment Rules (for Cases and Leads)

  6. Auto-response Rules (email notifications)

  7. Workflow Rules (field updates, email alerts)

  8. Process Builder / Flows (automation)

  9. Escalation Rules (for Cases)

  10. Post-commit Logic (email sending, async sharing calculations)

When to Use Before vs. After Triggers

  • Before Triggers: Use when you need to update or validate the same record that initiates the trigger.

  • After Triggers: Use when you need to access the record's ID or perform DML operations on related records.

Troubleshooting a Bulk Trigger Failure

Common issues include:

  • SOQL or DML operations inside loops

  • Lack of bulkification

  • Missing error handling

  • Recursive trigger execution

Trigger to Create a Contact When an Account is Created

An after insert trigger on the Account object can create a new Contact record and associate it with the new Account:

trigger CreateContactOnAccount on Account (after insert) {
    List<Contact> contactsToCreate = new List<Contact>();
    
    for (Account acc : Trigger.new) {
        contactsToCreate.add(new Contact(
            LastName = acc.Name + ' Contact',
            AccountId = acc.Id
        ));
    }
    
    if (!contactsToCreate.isEmpty()) {
        insert contactsToCreate;
    }
}


Comments (0)

Loading comments...

Leave a Reply