[SalesForce] Case Assignment Rule workaround

Background

I have an org where there are account teams. An account has a lookup field to a user that is the Customer Advocate for that account. I have triggers that add/edit/delete account team members for the account based on this lookup. So if I update an account that has no CA indicated on the account to a user, then the trigger adds that user as a new Account Team member with the role of CA. I know this seems like extra work for no reason, but this is what the client wanted, they wanted to only maintain that lookup field, and not have to add/edit/delete account team members, so I wrote the triggers to make that work.

Problem

In addition, if a certain case record type is created via the web, they would like the case to be assigned to the CA for that account. I have not been able to find a way to do this using case assignment rules. I was able to set up a CA queue, and assign it to the queue in the case assignment rules, but they would like it assigned to the specific person. In case assignment rules, you can really only assign to a specific user or queue, and can't really use any logic of any kind that I can see.

Proposed Solution

My idea to solve this would be to remove this criteria from the case assignment rules, and write a before insert trigger that will find the CA for the account and set them as the owner. This seems simple enough, and would be a fairly easy trugger to write. I have a few questions though

  • If this is a before insert trigger, will this owner persist, or will
    the default case assignment owner be set as the owner anyway.
  • Is there a way to access the 'Assign using assignment rules'
    attribute from the trigger so I can assure it isn't assigned using the
    assignment rules.
  • Is this the best solution? Am I jumping through hoops for no reason?
    Does someone have a better solution for this scenario? This is really my main question, I can likely run some tests to find answers for the previous, but I'm more looking to get input as to if this solution makes sense or am I missing something easier or more obvious.

Best Answer

If this is a before insert trigger, will this owner persist, or will the default case assignment owner be set as the owner anyway.

Assignment rules run after triggers do. See Triggers and Order of Execution for more details.

Is there a way to access the 'Assign using assignment rules' attribute from the trigger so I can assure it isn't assigned using the assignment rules.

You can't access the DML operations of the current transaction, as it is already underway. Therefore, the assignment rules will be triggered, and you cannot prevent this from occurring.

Is this the best solution? Am I jumping through hoops for no reason? Does someone have a better solution for this scenario? This is really my main question, I can likely run some tests to find answers for the previous, but I'm more looking to get input as to if this solution makes sense or am I missing something easier or more obvious.

Pass the ID values to a future method, and perform your ownership change asynchronously. This will allow you to reassign the user correctly after the assignment rule logic has executed.

Related Topic