ケースの割り当てルールを使用すると、ケースを適切なユーザーやキューに自動的にルーティングできます。ケースの割り当てルールは、ケースを割り当てるための条件と順序を定義する複数のルール項目で構成されます。複数のルール (例: [標準] ルールと [休日] ルール) を作成できますが、一度に「有効」にできるルールは 1 つだけです。
標準の UI では、ユーザーは [オプション] セクションの [有効な割り当てルールを使用して割り当てる] チェックボックスをオンにするだけで、割り当てルールをトリガできます。この問題は、アプリケーションによって Apex からケースを挿入する必要があり、割り当てルールをトリガする場合に発生します。このスクリプトを使用すると、ケースは挿入されますが、ケースに [有効な割り当てルールを使用して割り当てる] という項目がないため、割り当てルールがトリガされることはありません。
//Instance of case Case newCase = new Case(Status = 'New') ; //Inserting a Case insert newCase ;
Apex からケースの割り当てルールを実行する
解決策として、Database.DMLOptions を使用します。Database.DMLOptions クラスでは、トランザクション中に追加情報を提供できます。たとえば、項目の切り捨て動作や割り当てルール情報を指定できます。以下のスクリプトでは、ケースの割り当てルールを取得し、[有効な割り当てルールを使用して割り当てる] チェックボックスの DMLOptions を作成しています。
//Fetching the assignment rules on case AssignmentRule AR = new AssignmentRule(); AR = [select id from AssignmentRule where SobjectType = 'Case' and Active = true limit 1]; //Creating the DMLOptions for "Assign using active assignment rules" checkbox Database.DMLOptions dmlOpts = new Database.DMLOptions(); dmlOpts.assignmentRuleHeader.assignmentRuleId= AR.id; Case newCase = new Case(Status = 'New') ; //Setting the DMLOption on Case instance newCase.setOptions(dmlOpts); insert newCase ;
このスクリプトを使ってケースを挿入すると、割り当てルールがトリガされるようになりました。
000387623

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.