6

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.
8

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.

  • Thank you very much sfdc. Using a future method is indeed what I did to solve this a while back. Forgot to come back and answer this question though. Thank you, as this is exactly what I was looking for. – Chris Duncombe Jun 9 '14 at 13:38
  • 2
    @sfdc_ninja At least it's documented now. Hopefully it'll help someone in the future. – sfdcfox Jun 9 '14 at 13:47
  • N.B. if the assignment rules or subsequent workflows send emails, then those will be spurious as the async task's reassignment has yet to execute and notify the true user. The alternative solution is to have the first assignment rule assign to some 'pendingQ' based on a 1 time flag and then in the subsequent trigger firing, reassign as needed by detecting cases in the reassignQ and clearing the flag – cropredy Dec 31 '16 at 1:15
1

You are right here ,Assignment rules have the capability only to assign to specific user or queue and there is nothing as you rightly pointed out .

I would like to help you on your first and second question

1)I think in before insert trigger we can access the owner

2)For second trouble i am guessing that we can try following code in before trigger

for (Case objCase : Trigger.new) {
    Database.DMLOptions dmo = new Database.DMLOptions();
    dmo.assignmentRuleHeader.useDefaultRule = false;
    objCase.OwnerID = objCase.lookupfield__c;
    objCase.setOptions(dmo);
    }
}

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.