Skip to main content

I want our user raised ideas to automatically populate a slack channel for our internal business to view.

Thanks Joe
1 件の回答
  1. 2020年9月26日 11:32
    Hi Joe, 

    It should be possible. You need to customize your code accordingly and query for user raised idea. Here is a sample apex class that posts to slack. Please make changes according to your requirement

    public with sharing class SlackOpportunityPublisher {

    private static final String slackURL = 'YOUR_WEBHOOK_URL';

    public class Oppty {

    @InvocableVariable(label='Opportunity Name')

    public String opptyName;

    @InvocableVariable(label='Stage')

    public String stage;

    }

    @InvocableMethod(label='Post to Slack')

    public 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));

    }

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

    private final String url;

    private final String method;

    private final String body;

    public QueueableSlackCall(String url, String method, String body) {

    this.url = url;

    this.method = method;

    this.body = body;

    }

    public 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);

    }

    }

    }

    Reference: http://coenraets.org/blog/2016/01/slack-salesforce-integration/

     
0/9000