You need to sign in to do that
Don't have an account?
Shaun B.
Case Feed vs. Feed Comment
Hello (Developer) World!
I wrote (with the help of the community!) the following Apex code to update a case field anytime someone posts to the case feed. The issue I have now is that if someone replies to the feed comment instead of the feed item, my fields don't update. Can someone help me to modify or add to the below to achieve my desired result?
I wrote (with the help of the community!) the following Apex code to update a case field anytime someone posts to the case feed. The issue I have now is that if someone replies to the feed comment instead of the feed item, my fields don't update. Can someone help me to modify or add to the below to achieve my desired result?
trigger UpdateCaseCommentFields on FeedItem (after insert, after update) { List<Case> updates = new List<Case>(); for (FeedItem fi : Trigger.new) { if (fi.ParentId.getSObjectType() == Case.SObjectType && fi.Visibility == 'InternalUsers') { updates.add(new Case( Id = fi.ParentId, Last_Internal_Comment__c = fi.Body )); } else if (fi.ParentId.getSObjectType() == Case.SObjectType && fi.Visibility != 'InternalUsers') { updates.add(new Case( Id = fi.ParentId, Last_External_Comment__c = fi.Body )); } } update updates; }
My bad, please replace below line at line 7:
List<id> userList = new List<ID>();
Please try now, let me know if you still face issues on this.
Thanks,
Gaurav
Email: gauravgarg.nmims@gmail.com
All Answers
Please add one more trigger on FeedComment, below is the snippet:
Please try adding above trigger, and let me know if you face any issues.
Thanks
Gaurav
Email: gauravgarg.nmims@gmail.com
One more question, I am looking at the feedItemId.Visibility right now to set my fields, but how would I instead look at the User.UserType? I want to filter based on the following:
Please follow below steps:
1. List out all users (owners), just I did for FeedItem.
2. Query on user with respective field i.e.UserType and store it in map.
3. Update if condition for updating case record like:
Hope this will solve your problem.
Regards,
Gaurav
Email: gauravgarg.nmims@gmail.com
Please update code as below:
Try above code and let me know if you face some issues.
Thanks,
Gaurav
Email: gauravgarg.nmims@gmail.com
It appears to have an issue with:
Thanks!
My bad, please replace below line at line 7:
List<id> userList = new List<ID>();
Please try now, let me know if you still face issues on this.
Thanks,
Gaurav
Email: gauravgarg.nmims@gmail.com
Now if only I had a test class... :)
Hi Bailey,
Do you need the test class for above code?
Thanks,
Gaurav
Thanks again for all your help!
No Problem, you can contact me directly through email or skype. Below are my details
Email: gauravgarg.nmims@gmail.com
Skype: gaurav62990
Thank you