Auto-Assign Case to SLA Queue

Let’s imagine you have a support team, and some cases need special attention say, anything that’s high priority and comes in through the web.

Wouldn’t it be great if Salesforce could automatically assign those cases to a specific SLA Queue for faster handling?

That’s exactly what we’re going to build in this post a handy Apex method that checks the details of a Case and, if it meets the right conditions, assigns it to the “SLA Queue.”

🧠 What Are We Trying to Do?

 

We want to:

  • Accept a Case record.

  • Check if it’s High Priority and came from the Web.

  • If both conditions are true, update the case to be owned by a Queue named SLA_Queue.

This kind of automation helps reduce delays and ensures that urgent cases are handled by the right team.

🔍 Code Explanation

 
public with sharing class ApexUseCaseTwentyThree {
    public static final String priorityType = 'High';
    public static final String caseOrigin = 'Web';

We define two constants for Priority and Origin. That way, we can easily change these later without editing the logic.

    public static void reassignCaseBasedOnCriteria(Case caseRec){
        if(caseRec != null){

We begin our method, making sure the input Case record isn’t null.

            if(caseRec.Priority == priorityType && caseRec.Origin == caseOrigin){

Here we check whether the Case is both High Priority and created via Web. If it is, we continue.

                List<Group> mySLAQueue = [SELECT Id, Name, Type, DeveloperName 
                                           FROM Group 
                                           WHERE Type = 'Queue' 
                                           AND DeveloperName = 'SLA_Queue'];

We query the Group object, which holds Queue records in Salesforce.
We filter by:

  • Type = 'Queue'

  • DeveloperName = 'SLA_Queue' (this is the unique name of the queue in Setup)

 
                if(mySLAQueue.size() == 1){
                    caseRec.OwnerId = mySLAQueue[0].Id;
                    update caseRec;                    
                }

If exactly one matching Queue is found, we update the OwnerId on the case to that Queue’s ID and perform a DML update.

            }
        }
    }
}

Simple, clean, and effective!

✅ Why This Is Useful

This kind of logic is a great addition to any support process. You can:

  • Route urgent tickets directly to the right team

  • Ensure accountability by assigning owners based on rules

  • Extend the logic to handle other queues like Billing, Escalations, etc.

You could even integrate this into a trigger or a Process Builder flow that calls this method using @InvocableMethod.

🧾 Final Code Snippet

 
public with sharing class ApexUseCaseTwentyThree {
    public static final String priorityType = 'High';
    public static final String caseOrigin = 'Web';

    public static void reassignCaseBasedOnCriteria(Case caseRec){
        if(caseRec != null){
            if(caseRec.Priority == priorityType && caseRec.Origin == caseOrigin){
                List<Group> mySLAQueue = [SELECT Id, Name, Type, DeveloperName 
                                           FROM Group 
                                           WHERE Type = 'Queue' 
                                           AND DeveloperName = 'SLA_Queue'];
                if(mySLAQueue.size() == 1){
                    caseRec.OwnerId = mySLAQueue[0].Id;
                    update caseRec;                    
                }
            }
        }
    }
}

🎥 Watch It in Action!

 

Prefer to see it working instead? I’ve got a short video walking you through the code in the Developer Console and showing how a case is reassigned based on criteria.

Want to Apply As Content Writer?

Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Cart

Let's get you started!

Interested in writing Salesforce Content?

Fill in this form and we will get in touch with you :)