0

We have case assignment rule defined and we want to make process data driven. Is there a way we can modify case assignment rule with some apex coding?

2
  • 2
    I think you would be better off using an Apex Trigger. You can set the OwnerId based on data and be much more dynamic. Retooling actual Assignment Rules via Apex sounds horribly complicated.
    – Adrian Larson
    Oct 13 '16 at 19:25
  • I was waiting for a comment from @AdrianLarson thank you. We actually have everything in place, Utility class, wrapper and controller. I was wondering if we can use apex in any way to modify case assignment rules. Oct 13 '16 at 19:26
5

This can be done

You only get control before assignment rules run in before/after triggers so, you need to do the following

Option 1 (assumes you may want to keep some assignment rules)

  1. Create a new assignment rule that assigns to a queue called 'Pending Assignment Q'. Make it first in the sequence of rules
  2. Create a custom Boolean field on Case called is_custom_assignment__c
  3. Make the entry criteria for this assignment rule : is_custom_assignment__c = true
  4. Create before insert trigger logic so that is_pending_assignment__c is set to true if the new Case requires custom assignment logic. If it does not, then do nothing. Assignment rules 2...n will execute per normal.
  5. In before update trigger (which will be fired because the assignment rules will update the Case.OwnerId), see if case is owned by Pending Assignment Q. If yes, then apply your custom assignment logic. If not, do nothing.

Option 2 (assumes all assignment rules are custom)

Simply don't use Case Assignment rules and let your before insert trigger do all custom assignment by setting Case.OwnerId

2
  • This sounds like a solution, so what I can do is keep the existing assignment rule as is and do not touch them. But for new coming data if my conditions get fulfilled I can assign those cases using the before trigger. Problem here would be to accommodate this trigger with utility class that is already existing and creating a child case, grand child case and other logic. Oct 13 '16 at 19:29
  • the util class issue is something you'll have to deal with - doesn't really invalidate the above approach
    – cropredy
    Oct 13 '16 at 21:25
4

Assignment rules are metadata, and cannot be altered directly via Apex (cropredy's answer is a workable alternative).

As far as I know, they can only be altered via the Metadata API, which you also can't use directly via Apex.

You should be able to access the Metadata API by using FinancialForce's Apex Metadata API Wrapper.

In the end, this is a horribly complex and convoluted way to go about things, and is likely to end in tears. I wouldn't recommend this approach to anyone. If cropredy's first solution doesn't work for you, a trigger is the appropriate tool for the job.

1
  • Thank you for the information. I will be trying to write a trigger. Oct 13 '16 at 19:38

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.