[SalesForce] Case assignment and process builder which one get triggered first

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"

Best Answer

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.

Related Topic