You need to sign in to do that
Don't have an account?
Michael Foster 5
Challenged Invoking Lead Assignment Rule From Apex Code
Invoking Lead Assignment Rule From Apex Code
I am not having success. Can anyone help. I am an admin. Not a developer. New to APEX. I am running a app with an Apex Class Email Processor. Do I plug the code in the existing Apex Class Email Processor or create a new Apex Class? Do I use an existing or create a Visual Force page? Other? I tried adding to existing and the assignment rule is not working. I tried creating a new Apex Class, the code as is is not accepted. I also created a Visual Force page and the rule does not trigger.
//Fetching the assignment rules on case
02AssignmentRule AR = new AssignmentRule();
03AR = [select id from AssignmentRule where SobjectType = 'Case' and Active = true limit 1];
04
05//Creating the DMLOptions for "Assign using active assignment rules" checkbox
06Database.DMLOptions dmlOpts = new Database.DMLOptions();
07dmlOpts.assignmentRuleHeader.assignmentRuleId= AR.id;
08
09Case newCase = new Case(Status = 'New') ;
10//Setting the DMLOption on Case instance
11newCase.setOptions(dmlOpts);
12insert newCase ;
I am not having success. Can anyone help. I am an admin. Not a developer. New to APEX. I am running a app with an Apex Class Email Processor. Do I plug the code in the existing Apex Class Email Processor or create a new Apex Class? Do I use an existing or create a Visual Force page? Other? I tried adding to existing and the assignment rule is not working. I tried creating a new Apex Class, the code as is is not accepted. I also created a Visual Force page and the rule does not trigger.
//Fetching the assignment rules on case
02AssignmentRule AR = new AssignmentRule();
03AR = [select id from AssignmentRule where SobjectType = 'Case' and Active = true limit 1];
04
05//Creating the DMLOptions for "Assign using active assignment rules" checkbox
06Database.DMLOptions dmlOpts = new Database.DMLOptions();
07dmlOpts.assignmentRuleHeader.assignmentRuleId= AR.id;
08
09Case newCase = new Case(Status = 'New') ;
10//Setting the DMLOption on Case instance
11newCase.setOptions(dmlOpts);
12insert newCase ;
//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 ;
Use below trigger to fire the assignment rule on case creation via API:
trigger CaseAssignment on Case (after insert) {
//Variable decleration
List<Case> caseList = new List<Case>();
User integrationUserObj = new User();
if(Trigger.isAfter && Trigger.isInsert){
//Fetching the integration user details
integrationUserObj = [SELECT Id, Name FROM User where Name = 'Integration User' LIMIT 1];
for (Case caseObj : Trigger.new) {
if (caseObj.OwnerId == integrationUserObj.Id) {
caseList.add(new Case(id = caseObj.id));
}
}
Database.DMLOptions dmo = new Database.DMLOptions();
dmo.assignmentRuleHeader.useDefaultRule = true;
Database.update(caseList, dmo);
}
}
/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 ;