Problem

DunePoint, a chemical company, leverages Salesforce Service Cloud's case management system to effectively manage customer service inquiries. The company is seeking to improve their customer service operations by automating certain business process.


They intend to dynamically adjust account ratings based on the number of open cases, ensuring prompt attention to high-volume customers.


To accomplish this, the Salesforce team has chosen to develop an Apex trigger for automated rating updates based on case workload.


Complete the given apex trigger handler to satisfy this requirement.


Instructions :


1. If the number of open cases is more than 50, set the account rating to 'Hot'


2. If the number of open cases is more than between 25 to 50, set the account rating to 'Warm'


3. If the number of open cases is less than 25, set the account rating to 'Cold'

Note:
1. The case trigger has been deployed to your salesforce instance, and the provided AfterInsert method will be invoked for the "after insert" event.

2. Use trigger context variables (i.e., trigger.new) to access the records from the trigger handler.


Example:


//NewAccount
Insert new Account (name='Amazon USA');

//newCase
Insert new case(AccountId=NewAccount.Id, Status='New');

//Result
The priority on NewAccount will be set to 'Cold'


Hint:


The "Account" and "Cases" are standard objects in salesforce, connected through a lookup relationship. Cases have a standard field named "Account" with the API name "accountid".


In this scenario, when a case record is inserted or updated (to a closed status), the associated account requires an update. Utilize the 'after insert' and 'after update' trigger events on case object to determine the number of open cases for an account and adjust the rating accordingly.


Ensure that the trigger code is bulkified, using appropriate variable types to prevent any potential breaches of governor limits.