Skip to main content
Tarek Ayoubi (My Happy Place) a posé une question dans #Apex
Hi,

I would appreciate your help with the following Scenario:

For one client I have 2 accounts based on the location (siteID)

Account1 :

Name: "Client XYZ"                  // Account.name           (name)

Email: "clientxyz@gmail.com"  // account.Email__c    (email)

SiteID = 744888                      //account.SiteId__c      (picklist)

Account 2:

Name: "Client XYZ"

Email: "clientxyz@gmail.com"

SiteID = 418666

These accounts are not personal accounts and they don't have contacts so the email field is a custom field on the account.

 

When a case is created using the Email-to-case:

----------------------

Case Fields: 

case.origin   (Picklist) /// same values as account.SiteId__c  (418666 or 744888)

case.SuppliedEmail (email)

-------------------

The Account ID / Account name on the Cases is empty because we have 2 accounts with the same email address. 

I'm a beginner in apex triggers, may you please help me in writing a step-by-step trigger that would query the right account and triggers on case edit/creation.

Should we do this in two parts one part apex trigger and the second part Process builder?

Appreciate your help

T.
1 réponse
  1. 15 mai 2021, 07:01
    Hi Tarek Ayoubi 12,

    You can query your account according to your site like below 

     

    List<Account> accList = [ Select Id, Name, email__c from Account where SiteID = '418666'] //for 418666 site Id

    or

    List<Account> accList = [ Select Id, Name, email__c from Account where SiteID = '744888'] //for 744888 site Id

    If you find your Solution then mark it as the best answer. 

    Thanks and Regards

    Suraj Tripathi.