You need to sign in to do that
Don't have an account?
symantecAP
Updating Case Comment based on Task Description
Hi ALL
I am trying to write a trigger to update Casecomment depending on the Task Description and here is my code
trigger UpdateCaseCom on Task (after insert) { List<CaseComment> casecom = new List<CaseComment>(); for (Task t : Trigger.new) { if (t.subject=='Call'){ CaseComment cc = new CaseComment(); cc.ParentId = t.WhatId; cc.CommentBody = t.Description; casecom.add(cc); } update casecom; } }
This code gets saved but when i try to save the Task it gives me the error
Apex trigger UpdateCaseCom caused
an unexpected exception, contact your administrator: UpdateCaseCom:
execution of AfterInsert
caused by: System.DmlException: Update failed. First exception on row 0;
first error: MISSING_ARGUMENT, Id not specified in an update call: []:
Trigger.UpdateCaseCom: line 17, column 1
You are calling an Update DML statement and you are not providing an ID for the CaseComment.
You need to either:
1. Change the UPDATE statement to an INSERT statement.
2. Provide ID's for all the CaseComment objects.
Insert works fine, but update doesnt. if the description is changed then the case comment doesnt
how do i provide ids for above code
Ths short answer is you would need to Query to get all the CaseComments for the Case, then find the CaseComment that is related to this Task, and then update it accordingly.
But you may already see the problem here.
You don't have anyway to relate a CaseComment to your Task based on your code above.
CaseComment is looking up to Case based on ParentId. One Case can have many CaseComment's.
Task is looking up to Case based on ParentId. One Case can have many CaseComments'.
You could create a Junction Object between Task and CaseComment and relate the two objects that way. However, now your adding additional complexity.
Hi Cory,
how would you go about making a junction object for Tasks/Comments when Tasks don't support custom lookup fields or master-detail fields?
I tried to do something similar to record Task change history (due to another major flaw in Tasks) but came unstuck.
Cheers,
James.