You need to sign in to do that
Don't have an account?
DannyTK
Trigger to Save new Cases for Assignment rule
Good afternoon,
I'm working on a simple trigger that can save new cases generated by Process Builder in order for them to hit the assignment rules (Cases created via Process builder will not hit the assignment rules until the Case is Edited and Saved again), and have the following:
trigger caseUpdate on Case (after insert) {
List <Case> newCases = new List <Case>();
for (Case ticket : Trigger.new) {
ticket.Status = 'Pending Customer Information';
}
update newCases;
}
Can someone take a look to see if I missed anything, i'm not a developer so wanted to get a more experience eye on this to validate that it looks okay.
Thanks community
-danny
I'm working on a simple trigger that can save new cases generated by Process Builder in order for them to hit the assignment rules (Cases created via Process builder will not hit the assignment rules until the Case is Edited and Saved again), and have the following:
trigger caseUpdate on Case (after insert) {
List <Case> newCases = new List <Case>();
for (Case ticket : Trigger.new) {
ticket.Status = 'Pending Customer Information';
}
update newCases;
}
Can someone take a look to see if I missed anything, i'm not a developer so wanted to get a more experience eye on this to validate that it looks okay.
Thanks community
-danny
Please try below code and let me know if it works.
trigger caseUpdate on Case (before insert) {
if(Trigger.isInsert && Trigger.isBefore){
for (Case ticket : Trigger.new)
{
ticket.Status = 'Pending Customer Information';
Database.DMLOptions dmo = new Database.DMLOptions();
dmo.assignmentRuleHeader.useDefaultRule= true;
ticket.setOptions(dmo);
}
}
Best Regards,
-Vivek
All Answers
Please try below code and let me know if it works.
trigger caseUpdate on Case (before insert) {
if(Trigger.isInsert && Trigger.isBefore){
for (Case ticket : Trigger.new)
{
ticket.Status = 'Pending Customer Information';
Database.DMLOptions dmo = new Database.DMLOptions();
dmo.assignmentRuleHeader.useDefaultRule= true;
ticket.setOptions(dmo);
}
}
Best Regards,
-Vivek
doesn't seem like it worked, i'm wondering if it should be after insert. I'll keep testing, let me know if you have any other suggestions as well...I appreciate the help.
-danny
your trigger was slightly modified and it's working now, thanks for your help:
trigger caseUpdate on Case (after insert)
{
List<Case> caselist = new List<Case>();
if(Trigger.isInsert && Trigger.isafter)
{
for (Case ticket: Trigger.new)
{
caselist.add(new Case(id = ticket.id));
if(ticket.Status == 'Pending Customer Information')
{
Database.DMLOptions dmo = new Database.DMLOptions();
dmo.assignmentRuleHeader.useDefaultRule= true;
//ticket.setOptions(dmo);
Database.update(caselist,dmo);
}
}
}
}