function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Margaret FleischakerMargaret Fleischaker 

Fire case assignment rule in Lightning Data Service

I'm creating a case in a custom lightning component using the Lightning Data Service. If I wanted the case assignment rules to fire, would I also have to have an apex class that uses the Database.DMLOptions? I'm assuming I can't use the following directly from the javascript controller?
 
//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);


 
Best Answer chosen by Margaret Fleischaker
Maharajan CMaharajan C
Hi Margaret,

There is two Options here from my suggestion:

1. Use the After Insert Trigger in Case to keep the Lightning Data Service in your Lightning Component.

Trigger Examples:
https://www.salesforcexyz.com/category/salesforce/apex-trigger/
https://developer.secure.force.com/cookbook/recipe/running-case-assignment-rules-from-apex
https://www.forcetalks.com/blog/running-case-assignment-rules-from-salesforce-apex/
https://automationchampion.com/tag/run-case-assignment-rules-for-apex-trigger/
https://success.salesforce.com/apex/answers?id=90630000000D3SeAAK


2. Remove the LDS to insert the case record instead of that use the Server side Callback functionality(JS and Apex combination).From the JS pass the parameter to Apex to Insert the Case record and call this js function in button.

Can you please Let me know if it helps or not!!!

If it helps don't forget to mark this as a best answer!!!


Thanks,
Raj

All Answers

Complementary ComplementaryOneComplementary ComplementaryOne
Answer
Raj VakatiRaj Vakati
You can able to do it in multiple way s i belive 
 
@AuraEnabled
public static void getCase() {

//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);



}


Or set from the apex trigger .. 
Maharajan CMaharajan C
Hi Margaret,

There is two Options here from my suggestion:

1. Use the After Insert Trigger in Case to keep the Lightning Data Service in your Lightning Component.

Trigger Examples:
https://www.salesforcexyz.com/category/salesforce/apex-trigger/
https://developer.secure.force.com/cookbook/recipe/running-case-assignment-rules-from-apex
https://www.forcetalks.com/blog/running-case-assignment-rules-from-salesforce-apex/
https://automationchampion.com/tag/run-case-assignment-rules-for-apex-trigger/
https://success.salesforce.com/apex/answers?id=90630000000D3SeAAK


2. Remove the LDS to insert the case record instead of that use the Server side Callback functionality(JS and Apex combination).From the JS pass the parameter to Apex to Insert the Case record and call this js function in button.

Can you please Let me know if it helps or not!!!

If it helps don't forget to mark this as a best answer!!!


Thanks,
Raj
This was selected as the best answer