Advertisement
Guest User

Untitled

a guest
Sep 16th, 2014
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. trigger ActivityHistoryToChatter on Task (after insert, after update) {
  2. for(Task t : trigger.new)
  3. {
  4. //if it's now a completed task, and wasn't before
  5. //create the new chatter post.
  6. string what = t.whatID;
  7.  
  8. if(what.substring(0,3) == 'a19')
  9. /*
  10. The above line lets you control exactly which objects you want to toss this on. Adjust the If statement to the
  11. 3 digit object code for various elements.
  12.  
  13. Ex:
  14.  
  15. Cases - 500
  16. Accounts - 001
  17. Opportunities - 006
  18.  
  19. I STRONGLY suggest you use this if you're going to do a larger, longer demo, as you'll need to chatter enable any
  20. object you play with the task history on or this will crash. If you're not playing with Activity History/Tasks anywhere
  21. else, won't be a big deal.
  22. */
  23.  
  24. //{
  25. if(!t.alreadyPosted__c && t.status == 'Completed')//hasn't been posted, completed
  26. {
  27. Task daTask = [select id, description, whoid, activityDate, ownerid, subject from Task where id = :t.id];
  28. string whoelement = daTask.whoId;
  29. if (whoelement != NULL)
  30. {
  31. if(whoElement.substring(0,3) == '003')//contact
  32. {Contact who = [select name from Contact where id = :whoelement];
  33. whoElement = who.name;}
  34. else
  35. {Lead who2 = [select name from Lead where id = :whoelement];
  36. whoElement= who2.name;}
  37. }
  38. User owner = [select name from User where id = :daTask.OwnerId];
  39.  
  40. daTask.alreadyPosted__c = true;
  41.  
  42. FeedPost OppFeed = new FeedPost();
  43. string body = t.Subject + ' was completed by ' + owner.name + ' on ';
  44. body += t.activityDate.Month() + '/' + t.activityDate.Day() + '/' + t.ActivityDate.Year() + 'n';
  45. if(t.description != null)
  46. body += 'Comments: ' + t.description;
  47. OppFeed.body = body;
  48. oppFeed.parentID = t.whatID;
  49. oppFeed.linkURL = '/' + t.id;
  50. oppFeed.title = t.subject;
  51. insert oppFeed;
  52. }
  53. //}
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement