0

Scenario

I've custom field as picklist for differentiating case called Case Category. I've one process builder which assigns the value of Case category depending on Case Subject like if the case contains word wholesale it will get assigned to picklist value Wholesale or if it contains word ecommerce it will get assigned to picklist value Ecommerce.

I want to create Case assignment rules depending on its category like say if the Case Category is Wholesale it will get assigned to ABC if its Ecommerce it will get assigned to XYZ.

Question

I know the case assignment rules will be processed/checked on case creation(If I'm not wrong). But is there any sequence like the process builder will get triggered first then Case assignment rules (For process builder I've selected "Created or Edited").

I can assign it to one user in process builder but we have multiple persons who have to deal with those cases so I'm assigning those to Case Queue.

UPDATE

Trigger Code (Ignore typo for Assign and I know I've missed best practices while writing the trigger maybe for inserting object if I'm not wrong please correct me I'm new to this)

trigger AssigbCaseCategory on Case (before insert,before update) {
    List<Case> cases = new List<Case>();
    for(Case c : Trigger.new) {
        String case_subject = c.Subject;
        List<String> wholesale_keywords = new List<String>{'wholesale','Wholesae'};
        List<String> ecommerce_keywords = new List<String>{'ecommerce','Ecommerce'};
        Pattern wholesale_pattern = Pattern.compile(String.join(new List<String>(wholesale_keywords),'|'));
        Matcher wholesale_matcher = wholesale_pattern.matcher(case_subject);
        if(wholesale_matcher.find()) { 
            c.Case_Category__c = 'Wholesale';
        }   

        Pattern ecom_pattern = Pattern.compile(String.join(new List<String>(ecommerce_keywords),'|'));
        Matcher ecom_matcher = ecom_pattern.matcher(case_subject);
        if(ecom_matcher.find()) { 
            c.Case_Category__c = 'Ecommerce';
        }   
    }
}

My Case Assignment Rule

Sort order : 1

Run this rule if the : criteria are met

Field = Case:Case Category

Operator = equals

Value = wholesale

And I've assigned it to the different user(consider ABC)

TEST

I created a case where it was assigned to XYZ and I inserted "Test for wholesale in subject"

So Case Category is getting assigned properly but the user is still XYZ and If I'm not wrong it should be ABC. Right? Or I'm missing any fundamentals here"

2 Answers 2

2

The reference on Triggers and Order of Execution will be very important in cases like this:

  1. Executes assignment rules.

comes prior to

  1. Executes processes.

You may want to move your category-assignment logic to a Before Insert trigger

  1. Executes all before triggers.

for this reason and to avoid firing an additional DML operation.

6
  • Thanks for the link and guidance, so if I'm not wrong I must create a Trigger(before) where I will assign the appropriate case category based on Keywords and I will make assignment rule where I will just check the Case Category and will assign it to queue. Right? Apr 18, 2018 at 18:15
  • Sounds workable to me!
    – David Reed
    Apr 18, 2018 at 18:15
  • Alright, so I've created before trigger which will assign the Case Category value based on a subject which is working properly, I also have case assignment where I'm checking if the Case Category and assigning them to appropriate user. If I'm not wrong Case assignment rules arent get triggered if I update case or I'm wrong? Because it's not getting assigned to the user. I've also tried to create new case but it still failing to assign the user though before trigger is working fine. Apr 19, 2018 at 8:38
  • Are you doing before insert or before update?
    – David Reed
    Apr 19, 2018 at 13:28
  • I've updated my question and have inserted trigger snippet, please take look at that. Apr 19, 2018 at 14:16
1

According to the order of execution it's Assignment before Processes

Relevant snippet:

Executes assignment rules.
Executes auto-response rules.
Executes workflow rules.
If there are workflow field updates, updates the record again.
If the record was updated with workflow field updates, fires before update triggers and after update triggers one more time (and only one more time), in addition to standard validations. Custom validation rules, duplicate rules, and escalation rules are not run again.
Executes processes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.