A company utilizing salesforce service cloud to manage customer requests has implemented a new process for handling inbound calls. With the new process, customer interactions are systematically recorded as cases within Salesforce.
Management at the company is seeking a mechanism to monitor the type of activities performed by their staff to resolve cases, facilitating more effective resource allocation.
To address this business requirement, the salesforce team at the company has opted to implement an apex trigger to log tasks automatically when a case is created with the origin 'Phone'.
Complete the given apex trigger handler to implement this requirement.
Instructions
- Create a task when a case is created, and the case origin is set to 'Phone'.
- Set the WhatId field of the task to the Account ID associated with the case.
- Set the task description to the case number.
- Set the task status to 'Completed'.
- The case trigger has been deployed to your organization, and the provided afterInsert method will be invoked for the "after insert" trigger event.
- Use trigger context variables (i.e., trigger.new) to access the records from the trigger handler.
Example
Insert new case(AccountId='001QE000005bQLq', Origin='Phone');
//Result
Task created on account (id='001QE000005bQLq') with status completed, case number populated on the description
Hint
- "Account" and "Cases" are standard objects in Salesforce, linked through a lookup relationship. Cases have a standard field named "Account" (API name accountid).
- In this scenario, the insertion of a record triggers the insertion of a record in another object. Utilize the "after" trigger event to handle this scenario.
- The trigger code has the capability to process up to 200 records in a transaction. Therefore, ensure that the trigger code is bulkified, using appropriate variable types to mitigate any potential breaches of governor limits.