function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rohit Vaidya 3Rohit Vaidya 3 

Case assigned to agent

we have 3 agents and the inflow of cases  , how to assign cases to these agents using declarative method and Apex , the type and other properties of the case are not taken into consideration.
SwethaSwetha (Salesforce Developers) 
HI Rohit,

>> You can create a Case Assignment Rule that assigns cases to the three agents in a round-robin fashion. Then create a Case Queue for each of the three agents.

Assign the cases to the Case Queues using the Case Assignment Rule created earlier. This will ensure that the cases are assigned to the three agents in a round-robin fashion

See https://trailhead.salesforce.com/content/learn/projects/set-up-case-escalation-entitlements/create-case-queues-assignment-rule

>> If you want to use Apex to assign cases to the agents, you can create an Apex trigger that fires when a new case is created. The trigger can then assign the case to one of the three agents in a round-robin fashion.
 
trigger CaseAssignTrigger on Case (before insert) {
    // Get all active agents from the User object
    List<User> activeAgents = [SELECT Id FROM User WHERE IsActive = true AND Profile.Name = 'Your_Agent_Profile_Name'];

    if (activeAgents.isEmpty()) {
        // If there are no active agents, do not proceed with assignment
        return;
    }

    Integer agentCount = activeAgents.size();
    Integer currentIndex = 0;

    for (Case newCase : Trigger.new) {
        // Round-robin assignment logic
        User assignedAgent = activeAgents[currentIndex];
        newCase.Assigned_Agent__c = assignedAgent.Id;
        
        // Move to the next agent in the list
        currentIndex = (currentIndex + 1) % agentCount;
    }
}

Related: 
Run Case Assignment Rule from Apex: https://help.salesforce.com/s/articleView?id=000387623&type=1

https://cynoteck.com/blog-post/salesforce-case-management/

If this information helps, please mark the answer as best. Thank you
jixalo maryajixalo marya
It is one of the best site that I have visited. Hope you will share more quality blog
posts thank you. MyKFCExperience (https://www.diigo.com/item/note/ajn14/p6qx?k=6a79ab69b407feb11c2743d51cb145ac" target="_blank)