6

I'm trying to create a POC for reputation levels / capturing changes in a trigger. I've seen various Salesforce docs that mention this is possible with NetworkMember triggers:

  1. NetworkMember object reference. Scroll to Usage section, highlighted in yellow box.
  2. Chatter API sample code. Scroll to Assign a Recognition Badge When a Member Reaches a Number of Reputation Points section.

I've verified reputation points are increasing after a post, comment, like, etc. but for some reason the NetworkMember trigger is not invoked. No debug logs are created.

Any ideas why this is happening?

NetworkMemberTrigger.trigger

trigger NetworkMemberTrigger on NetworkMember (before insert, after insert, before update, after update) {
    NetworkMemberTriggerHandler.handleTrigger(Trigger.new, Trigger.oldMap, Trigger.operationType);
}

NetworkMemberTriggerHandler.cls

public with sharing class NetworkMemberTriggerHandler {
    public static void handleTrigger(List<NetworkMember> newRecords, Map<Id, NetworkMember> oldMap, System.TriggerOperation triggerEvent) {
        switch on triggerEvent {
            when BEFORE_INSERT { handleBeforeInsert(newRecords); }
            when AFTER_INSERT  { handleAfterInsert(newRecords); }
            when BEFORE_UPDATE { handleBeforeUpdate(newRecords, oldMap); }
            when AFTER_UPDATE  { handleAfterUpdate(newRecords, oldMap); }
        }
    }

    public static void handleBeforeInsert(List<NetworkMember> newRecords) {
        System.debug('============ NETWORK MEMBER - BEFORE INSERT ===========');
    }

    public static void handleAfterInsert(List<NetworkMember> newRecords) {
        System.debug('============ NETWORK MEMBER - AFTER INSERT ===========');
    }

    public static void handleBeforeUpdate(List<NetworkMember> newRecords, Map<Id, NetworkMember> oldMap) {
        System.debug('============ NETWORK MEMBER - BEFORE UPDATE ===========');
    }

    public static void handleAfterUpdate(List<NetworkMember> newRecords, Map<Id, NetworkMember> oldMap) {
        System.debug('============ NETWORK MEMBER - AFTER UPDATE ===========');
        for(NetworkMember member : newRecords) {
            System.debug('Reputation Points: ' + member.ReputationPoints);
            System.debug('Last Chatter Activity Date: ' + member.LastChatterActivityDate);
        }
    }
}
2
  • 1
    Just double-checking the basics: your trigger is Active in the org, right? If you persist a change to an sObject rather than executing a debug log, do you get any evidence that the trigger is running?
    – David Reed
    May 3, 2021 at 18:58
  • 3
    @DavidReed Yes, trigger is active. When I change ReputationPoints in Query Editor it does invoke the NetworkMember trigger. But if I ask a question or receive an upvote within my site/Chatter, the reputation increases but the trigger is not invoked. May 3, 2021 at 19:03

2 Answers 2

5
+200

You can view logs for your NetworkMember trigger by adding a debug log on Automated Process.

Navigate to Setup > Debug Logs. Click New under User Trace Flags. For "Traced Entity Type", select "Automated Process".

Figured this out by inserting an Account inside the NetworkMember trigger. The "user" that was creating those Accounts was the Automated Process.

1
2

I was able to reproduce this scenario in my org and then verified our Salesforce internal logs that the trigger on NetworkMember is being fired and there are no errors in this process.

This behavior is working as designed. When the trigger is fired the debug logs are generated in the context of the Automated process.

Typically, triggers run in the context of the running user but certain operations may need to be evaluated in the context of Automated Process users.

Some examples are Transaction Security Policies, Platform Events, event processes, and resumed flow interviews, and more. Also see similar post.

I have documented this information so it can help others in the future.

KnowledgeArticle link: https://help.salesforce.com/articleView?id=000358278&type=1&mode=1

1
  • Thanks for sharing! Frustrating I couldn't find this knowledge article - but helpful nonetheless. May 7, 2021 at 19:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .