A company utilizing Salesforce Service Cloud seeks to actively monitor cases created within the system to provide additional support to their customers in the event of multiple issues arising on the same day. The agreed threshold is three, and if more than three cases are created, the system needs to log a notification.
The Salesforce team has chosen to implement an apex trigger that will create a task on the related account when more than three cases are generated on the same day.
Complete the apex trigger handler to satisfy this requirement.
Instructions:
1. Examine the inbound case’s account and determine the total number of cases created in the system today.
2. If the count from step 1 exceeds three, initiate the creation of a task on the associated account.
3. Set the 'What Id' of the task to be the account id of the corresponding case.
4. Set the priority of the task to 'High.' and status to 'New.'
Note:
1. The case trigger has been deployed to your organization, and the provided afterInsert method will be invoked for the "after insert" trigger event.
2. Use trigger context variables (i.e., trigger.new) to access the records from the trigger handler.
Example:
//input - Inserting the 4th case
Insert new case(AccountId='001QE000005bQLq', Origin='Phone');
//Result
Task created on account (id='001QE000005bQLq') with status ‘New’ and priority ‘High’.
Hint: 'Account' and 'Cases' are standard objects in Salesforce, linked through a lookup relationship. Cases contain a standard field named 'Account' (API name: accountid).
In this scenario, the insertion of a record (Case) triggers the insertion of a record in another object (Task). Utilize the 'after' trigger event to handle this scenario.
It's important to note that the trigger code can process up to 200 records in a transaction. Therefore, ensure the trigger code is bulkified, utilizing appropriate variable types to prevent potential breaches of governor limits.