1

I am trying to use following apex class with invocable method but its not showing in process builder.

global with sharing class SlackOpportunityPublisher {

    private static final String slackURL = 'https://testsalesforceapps.slack.com/';

    global class Oppty {
        @InvocableVariable(label='Opportunity Name')
        global String opptyName;
        @InvocableVariable(label='Stage')
        global String stage;
    }

    @InvocableMethod(label='Post to Slack')
    global static void postToSlack(List<Oppty> oppties) {
        Oppty o = oppties[0]; // If bulk, only post first to avoid overloading Slack channel
        Map<String,Object> msg = new Map<String,Object>();
        msg.put('text', 'The following opportunity has changed:\n' + o.opptyName + '\nNew Stage: *' + o.stage + '*');
        msg.put('mrkdwn', true);
        String body = JSON.serialize(msg);    
        System.enqueueJob(new QueueableSlackCall(slackURL, 'POST', body));
    }

    global class QueueableSlackCall implements System.Queueable, Database.AllowsCallouts {

        private final String url;
        private final String method;
        private final String body;

        global QueueableSlackCall(String url, String method, String body) {
            this.url = url;
            this.method = method;
            this.body = body;
        }

        global void execute(System.QueueableContext ctx) {
            HttpRequest req = new HttpRequest();
            req.setEndpoint(url);
            req.setMethod(method);
            req.setBody(body);
            Http http = new Http();
            HttpResponse res = http.send(req);
        }

    }

}
  • I suppose your process builder on Opportunity. – Raul Sep 27 '17 at 14:14
  • yes you are right! – sekhar Sep 27 '17 at 14:17
  • Changing signature of class and/or method to public make any difference? – Raul Sep 27 '17 at 14:21
  • I tried before with public also but that time also faced same problem – sekhar Sep 27 '17 at 14:25
  • 1
    I copy pasted your class in my dev org and it works!! Issue is similar to this question. Try creating a new class and see if it appears? – Raul Sep 27 '17 at 14:34
6

This problem often resolves itself by going to Setup | Develop | Apex Classes | select the test class and then run tests. SFDC needs to be sure class has been tested to appear in dropdown.

Solution also applies to Schedulable classes, Inbound Email Handler classes

  • Great to know the solution. Thanks for sharing. But this doesn’t make sense, shouldn’t it register the class while creation? Also would compile all classes also work instead of running test class? – Raul Sep 27 '17 at 18:13
  • 1
    @RahulSharma - all I can say is I learned this trick from elsewhere and it works – cropredy Sep 27 '17 at 23:44
  • 2
    @Raul I can confirm the compile all classes solution works, independent of test coverage. In a dev org, I have methods that show up after 'compile all' that have no coverage whatsoever. – Vince Feb 7 at 19:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.