function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Scott Hirsch 7Scott Hirsch 7 

NullPointerException in Salesforce for Slack. How to understand how managed package is failing?


I'm attempting to deploy some new code and our test class is failing due to the following error:

System.NullPointerException: Attempt to de-reference a null object
Stack Trace: Class.slackv2.invokePostMessage.makePostMessageRequest: line 30, column 1

We have the Salesforce for Slack ( app installed in our Org. According to the setup instructions, we have a Process Builder created to send a notification to Slack when a new Opportunity is created. If I disable this Process Builder, I am able to deploy the code. However, I don't want to have to disable this Process Builder every time I deploy in the future. The code in managed packages is not visible so I cannot determine exactly what I need to do 

Does anyone have a suggestion on how I can determine what the managed package class needs?

Here's the test class and the class itself:
private class testCreateOpp {
    static testMethod void validateOpp() {
        // Create a new email and envelope object
        Messaging.InboundEmail email = new Messaging.InboundEmail() ;
        Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();
        // Populate email
        email.plainTextBody = 'Body text';
        email.subject = 'Subject Line of Email';
        // Execute method
        createOpp createOppObj = new createOpp();
        createOppObj.handleInboundEmail(email, env);

global class createOpp implements Messaging.InboundEmailHandler {
    global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, Messaging.InboundEnvelope env){
        // Create an InboundEmailResult object for returning the result of the Apex Email Service 
        Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
        String myPlainText= email.plainTextBody;
        String OppAccountId = '0014600000A0aaaAAA';
        // New Opportunity to be created
        Opportunity newOpp = new Opportunity(Name = email.subject, 
            AccountId = OppAccountId, 
            CloseDate = + 15,
            Description = myPlainText, // Email Body
            StageName = 'Identified',
            Amount = 5000);
        // Insert new Opportunity
        insert newOpp;    
        // Set the result to true. No need to send an email back to the user with an error message   
        result.success = true;
        // Return the result for the Apex Email Service 
        return result;
Scott Hirsch 7Scott Hirsch 7
Manually creating an Opportunity with the same parameters does not cause the error. It only seems to be when the test class is run.
Scott Hirsch 7Scott Hirsch 7
This is the invokePostMessage class definition.

Class definition for invokePostMessage.
Process Builder to post to Slack

Process Builder to post to Slack
Did you ever figure this out? Today I can't even deploy when the pb is deactivated!
Scott Hirsch 7Scott Hirsch 7
Sorry, unfortunately this is still causing issues for me today. Every deployment I have to disable our Process Builder so the Slack class doesn't fail. I've installed the latest version of the Slack app from the Appexchange hoping that would resolve it but it didn't. I'm hopeful that Salesforce's acquisition of Slack places more emphasis on fixing this. Please let me know if you figure anything out.
This is definitely still a bug in the Slack managed package - Slackforce you should get on this one!
Same thing happens for me.
Scott Hirsch 7Scott Hirsch 7
Installing the newer version (1.84) of the Slack package did not resolve this issue still and it actually broke our existing Process Builder on the Opportunity. The PB no longer posts messages to Slack. I do not recommend installing the newer version yet.
Scott Hirsch 7Scott Hirsch 7
I've been in contact with Slack support and they have a fix for this test class issue built into their next release (1.85). For anyone that experienced a failure of their existing Process Builders the "Message" parameter of the Slack: Post Message class is now required so you have to add that or the process will fail.
Lori GordonLori Gordon
I was able to get mine to work with 1.84 by adding the Message parameter and making sure my PB was a API version 52