You need to sign in to do that
Don't have an account?
Amr Mohsen
Trigger to change Case status after adding new task
Hello,
I need to change Case status After adding task to that case
My Code is
But I get the following error when I try to add new task
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger OnTaskAdded caused an unexpected exception, contact your administrator: OnTaskAdded: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.OnTaskAdded: line 6, column 1
I need help please.
I need to change Case status After adding task to that case
My Code is
trigger OnTaskAdded on Task (before insert) { try{ Task insertedTask = trigger.new[0]; Case caseToUpdate = insertedTask.What; caseToUpdate.Status = 'In Progress'; update caseToUpdate; }catch(DmlException e) { System.debug('An unexpected error has occurred: ' + e.getMessage()); } }
But I get the following error when I try to add new task
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger OnTaskAdded caused an unexpected exception, contact your administrator: OnTaskAdded: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.OnTaskAdded: line 6, column 1
I need help please.
Please check the below code.
Please do let me know if it helps you.
Regards,
Mahesh
I need to add a condition of task status is opened and also update numeric field in the case
I get error again, can you help me please.
c.Open_Tasks__c = Integer.valueOf(c.Open_Tasks__c) + 1;
is it something like
c.Open_Tasks__c = Integer.valueOf(t.Open_Tasks__c) + 1;
Regards,
Mahesh
If you can explain more about your actual requirement then we will be able to help you.
Regards,
Mahesh
Please find the below modified code:
Here I used the status as 'Not Started', if you want, you can change it accordingly.
I also tested the above code in my DE environment and everything looks good.
Regards,
Mahesh