SF for Outlook assigns case without using case assignment rules by design ... anybody come up with a work around? - Answers - Salesforce Trailblazer Community
Trailblazer Community
Ask Search:
Mark WoodwardMark Woodward 

SF for Outlook assigns case without using case assignment rules by design ... anybody come up with a work around?

According to this article, this is by design ...


Basically, SF for Outlook will assign new cases from email to default user/group; however, the additional Case Assignment Rules won't process.  I've already got lots of assignment rules and don't want to have to replicate elsewhere.  And I don't want the Create Case dropdown in Outlook to have lots of choices.

Anybody figure out a way to work around this limitation to use the Case Assignment Rules already setup?
Stephanie PoormanStephanie Poorman

I haven't done this work around exactly, but I've used the various pieces.  Assuming you're setting a case origin that is unique to SF for Outlook (since it's basically set up like email to case), you can fire off a process (when a case is created with that origin) that triggers an invocable method:
User-added image
In my case, I'm passing in the case assignment rule Id so that I have the option of using the same code to trigger different assignment rules (since you can run a rule that is not active, i.e. set as default).  You could, alternatively, just have your method choose the default case assignment rule (I'll show how below), in which case you'd just pass in the Case Id.

Create your invocable method, by creating a new class (you'll have to do this in a sandbox, then push it to Production):
Created on 3/10/17 by Stephanie Poorman
This class is an invocable method used by process Process_Case_Case Assignment Rules to run
cases through a Case Assignment Rule specified by an invocable variable in class AssignCasesVariables.

public class AssignCasesUsingAssignmentRules {
    public static void CaseAssign(List<AssignCasesVariables> variables) {
        for(AssignCasesVariables v: variables) {
            Database.DMLOptions dmo = new Database.DMLOptions();
            dmo.assignmentRuleHeader.assignmentRuleId= v.ruleId;          
            Case c = [SELECT Id FROM Case WHERE Case.Id = :v.CaseId.Id];
            update c;
If you just want to call the default case assignment rule, change the code to this:
public static void CaseAssign(List<Id> CaseIds) {
            Database.DMLOptions dmo = new Database.DMLOptions();
            dmo.assignmentRuleHeader.useDefaultRule= true;          
            Case Cases=[SELECT Id FROM Case WHERE Case.Id in :CaseIds];
            update Cases;
(You may have to tweak another couple things, but the key changes are that you don't need to add the mention of AssignCasesVariables and you change the assignmentRuleHeader property from assignmentRuleId to useDefaultRule.)

If you do choose to pass in the rule Id, you'll need a second class:
Created on 3/10/17 by Stephanie Poorman
This class is used to pass additional parameters from the process Process_Case_Case Assignment Rules
to invocable method class AssignCasesUsingAssignmentRules.

public class AssignCasesVariables {
  @InvocableVariable(label='Case Assigment Rule Id' required=true)
  public String ruleId;
  @InvocableVariable(label='Case Id' required=true)
  public Case CaseId;
I only have a test class to share for the pass-in-the-rule-Id method, but here it is:
Created on 3/10/17 by Stephanie Poorman
This test creates a new lead, assigns it to an active admin, then submits it to the AssignCasesUsingAssignmentRules invocable method.
The invocable method should run the cases through the case assignment rule "For Apex Tests Only".

public class AssignCasesUsingAssignmentRulesTest{

    static testMethod void assignNewCaseWithRule() {
        Id caseOwner1 = [SELECT Id FROM User WHERE Profile.Name = 'System Administrator' AND Alias != 'Data' AND isActive = true LIMIT 1].Id;
        Id rtBelden = [SELECT Id FROM RecordType WHERE SobjectType = 'Case' AND DeveloperName = 'InternalSupport' LIMIT 1].Id;
        Id caseOwner2 = [SELECT Id FROM User WHERE Alias = 'Data' LIMIT 1].Id;
        Id ruleId = [SELECT Id FROM AssignmentRule WHERE Name = 'For Apex Tests Only' AND SobjectType = 'Case' LIMIT 1].Id;

        Case newTestCase = new Case();
        newTestCase.OwnerId = caseOwner1;
        newTestCase.Subject = 'Test';
        newTestCase.Origin = 'Email';
        newTestCase.Priority = 'Medium';
        newTestCase.Status = 'New';
        newTestCase.RecordTypeId = rtBelden;
        newTestCase.Description = 'Test case created by Apex class AssignCasesUsingAssignmentRulesTest';    
        insert newTestCase;
        AssignCasesVariables v = new AssignCasesVariables();
        v.ruleId = ruleId;
        v.CaseId = newTestCase;
        AssignCasesUsingAssignmentRules.CaseAssign(new list<AssignCasesVariables>{v});
        caseOwner1 = [SELECT OwnerId FROM Case WHERE Id = :newTestCase.Id LIMIT 1].OwnerId;
        System.assertEquals(caseOwner2,caseOwner1,'The case owner should have updated to Belden Admin.');

You'll obviously need to adjust the test class to make sure you account for your instance's required fields and validation rules.

Hope this helps,