Skip to content

Flow Name: Before Create or Update Case

Last Updated: 2024-10-23 Source Code: Before_Create_or_Update_Case.flow-meta.xml

API Name: Before_Create_or_Update_Case Status: Active Type: Custom Trigger: Before save (create and update) of Case records when SuppliedEmail is populated or changed

Business Purpose

This flow automatically associates Cases with the correct Person Account by matching the Case's SuppliedEmail with existing Person Account email addresses. This ensures proper case ownership and enables accurate customer service tracking by linking web-to-case submissions and manually created cases to known customers.

Process Flow

  1. Email Validation: Checks if Case.SuppliedEmail field has a value (is not null)
  2. Account Lookup: Queries Person Accounts to find a match where PersonEmail equals the Case.SuppliedEmail
  3. Account Association: If matching Person Account is found, updates Case.AccountId with the found account
  4. Default Handling: If no email is supplied, clears the AccountId field to ensure clean data
📊 Click to view Process Flow Diagram
flowchart TD
    Start([Start: Case Create/Update<br/>Before Save Trigger]) --> EmailCheck{SuppliedEmail<br/>Populated or<br/>Changed?}

    EmailCheck -->|No| End([End])
    EmailCheck -->|Yes| HasEmail{SuppliedEmail<br/>Not Null?}

    HasEmail -->|No| ClearAccount[Clear AccountId Field]
    HasEmail -->|Yes| Lookup[Find Person Account<br/>where PersonEmail =<br/>SuppliedEmail]

    Lookup --> Found{Account<br/>Found?}

    Found -->|Yes| SetAccount[Set Case.AccountId<br/>to Found Account]
    Found -->|No| End

    ClearAccount --> End
    SetAccount --> End

    style Start fill:#e1f5ff
    style EmailCheck fill:#fff4e1
    style HasEmail fill:#fff4e1
    style Lookup fill:#f0e1ff
    style Found fill:#fff4e1
    style ClearAccount fill:#ffe1e1
    style SetAccount fill:#ffe1e1
    style End fill:#e1f5ff

Key Business Rules

  • Only triggers when SuppliedEmail field is not null or when SuppliedEmail field changes
  • Searches for exact email match in PersonEmail field of Account records
  • Uses first matching account if multiple accounts exist with same email
  • Clears AccountId if no SuppliedEmail is provided
  • Applies to both case creation and updates

Dependencies

  • Case standard object with SuppliedEmail field
  • Account standard object with PersonEmail field
  • PR-31251 (referenced in description)
  • Web-to-Case or Email-to-Case functionality that populates SuppliedEmail

⚠️ Pre-Go-Live Concerns

CRITICAL - Fix Before Go-Live

  • Duplicate Email Handling: Uses getFirstRecordOnly but doesn't validate which account is most appropriate when multiple Person Accounts have same email
  • Data Integrity: No validation that the found account is active or appropriate for case assignment

HIGH - Address Soon After Go-Live

  • Performance: Lookup runs on every case with supplied email - consider indexing PersonEmail field
  • Email Normalization: No email case standardization (user@email.com vs User@Email.COM treated as different)

MEDIUM - Future Enhancement

  • Account Preference: Could prioritize active members or most recently updated accounts when duplicates exist
  • Audit Trail: No logging of automatic account assignments for troubleshooting

LOW - Monitor

  • Field Dependency: Relies on SuppliedEmail being populated by external processes
  • Edge Cases: Doesn't handle invalid email formats or edge cases in email matching

Maintenance Notes

Complexity: Low - Simple lookup and assignment logic. Review quarterly to monitor email matching accuracy and duplicate account scenarios. Consider performance optimization if case volume increases significantly.