You need to sign in to do that
Don't have an account?
DONALD REBLITZ
Help Writing a Trigger
Bear with me as this is my first post on the dev community but looking for some help writing a relatively simple trigger (my first).
I have a related list on the case object called 'dispatch__c'. When a dispatch is updated to a status of 'Closed' I'm simply trying to post a case comment (or Chatter post) back to the related case. The case comment would simply read "Dispatc DISP-0123 was updated to 'Closed'". Is this possible and can someone point me in the right direction?
I have a related list on the case object called 'dispatch__c'. When a dispatch is updated to a status of 'Closed' I'm simply trying to post a case comment (or Chatter post) back to the related case. The case comment would simply read "Dispatc DISP-0123 was updated to 'Closed'". Is this possible and can someone point me in the right direction?
You will need to replace "CaseLookupField__r.id" to your lookup field to the cas eon your dispatch record before saving thsi trigger to alleviate errors. What we are doing is for any Dispatch records updated to Closed for its status we are loopign through those records being introduced to the trigger and for thos erecords we are creating a case comment for each case with the information you provided.
Then outside of that for loop we will insert the list of case comments that are being gathered to ensure your trigger is bulkified.
It this works for you please mark as the best answer, and if youhave any other questions, pleas elet me know,
Shawn
Just one note to add to Shawn's response, your trigger will need to run after update to be able to insert records, I would also expand the if statement to check the status has actually changed to closed.
this should help you add a chatter post to the parent case
- closedDispatch (Variable does not exist: ParentID) Line 9
- closedDispatch (Variable does not exist: CommentBody) Line 10
ParentId and Comment body are both fields on the new CaseComment, try this
You can't run a trigger directly from the developer console, you need to insert or update a record you expect the trigger to run on, so in this case you would wan to find an existing Dispatch__c record and update it's status to 'Parts Delivered'
I also forgot, you need to change line 1, the trigger should run after update
so in the dev console use something like this,
this will find an existing record and update it's status, then once the update is complete your trigger will run and put a comment on the parent case.
Don't forget to change the trigger to after update.