Print this page

Topics: Trigger on Delete and Debug Logs

Knowledge Article Number 000199453
Description Topics can be enabled for objects and can be added, updated or deleted. However, Deleting topics is slightly different from deleting records. Triggers, run when topics are deleted, don't show up in Debug logs. 
With or without Chatter enabled, administrators can enable topics for objects, letting users add topics to records so they can quickly retrieve related items using list views. With Chatter enabled, users can also see related items on the Records tab of each topic detail page. Enabling topics for an object disables public tags on records of that object type. Personal tags aren’t affected.
Deleting topics is slightly different from deleting records. When deleting topics, consider these points.
- Topics are permanently deleted. They aren’t sent to the Recycle Bin.
- Deleted topics are removed from search results, the topics list, all posts and records, Recently Talked About topics, Related Topics, and your users’ favorites. Deleted topics are removed from Trending Topics after the next calculation.
- Users can reintroduce a topic after it’s been deleted.
As per standard Salesforce Trigger functionality, users can add triggers on Topics for Insert, Update and Delete. Insert and Update topic triggers can be captured via debug logs. However, because topics are deleted by automated process, this activity is not captured in debug logs. However, there is an easier way to confirm that triggers on topic are actually working by adding code at the end of this article.
Once the automated process deletes topics (marked for deletion), triggers will be fired as per normal (except no entry in debug logs).
Sample Apex Code:
public class Mail{ 
  public static void sendDemoMail(String subject,String body){ 
    String to = 'EMAIL ADDRESS'; 
    String[] toAddresses = new String[] {to}; 

    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); 
    mail.setSubject('Automated Demo Mail: ' + subject); 
    Messaging.sendEmail(new Messaging.SingleEMailMessage[]{mail}); 
In trigger, add following:
trigger TopicDelete on Topic (before insert, before delete, before update, after insert, after update, after delete) {
    if(trigger.isBefore && trigger.isDelete){
        Mail.sendDemoMail('BEFORE Delete Trigger', 'Test');
    if(trigger.isAfter && trigger.isDelete){
        Mail.sendDemoMail('AFTER Delete Trigger', 'Test');

promote demote