有没有办法在 Salesforce 的 apex 类主体中创建超链接?

发布于 2025-01-09 07:29:17 字数 2118 浏览 1 评论 0原文

我正在使用 这个< /a> 作为在 Salesforce 中关闭/赢得机会时创建 Slack 通知的参考。

但是,我想知道是否有办法将机会的链接包含在 Apex 类主体中。

这是我到目前为止所得到的:

public with sharing class SlackPublisher {
 
private static final String SLACK_URL = 'HIDDEN URL';
 
public class Oppty {
    @InvocableVariable(label='Opportunity Name')
    public String opptyName;
      @InvocableVariable(label='Opportunity Owner')
    public String opptyOwnerName;
    @InvocableVariable(label='Account Name')
    public String acctName;
    @InvocableVariable(label='Amount')
    public String amount;
}
 
@InvocableMethod(label='Post to Slack')
public static void postToSlack ( List<Oppty> opps ) {
    Oppty o = opps[0]; // bulkify the code later
    
    Map<String,Object> msg = new Map<String,Object>();
     msg.put('text','Deal ' + o.opptyName + ' was just Closed/Won' + ':champagne:' + '\n' + 'for a total of ' + '$' + o.amount + '\n' + ' Check out the details in the document links below');
    msg.put('mrkdwn', true);

    
    String body = JSON.serialize(msg);   
    System.enqueueJob(new QueueableSlackPost(SLACK_URL, 'POST', body));
}
 
public class QueueableSlackPost implements System.Queueable, Database.AllowsCallouts {
     
    private final String url;
    private final String method;
    private final String body;
     
    public QueueableSlackPost(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);
    }
}
}

它向 Slack 发送一条消息,如下所示:

Slack 通知图像

什么我正在寻找一种使 opptyName(Gary Test 1 - Kong)成为超链接的方法,或者在末尾添加机会 URL。

I'm using this as reference to create a Slack notification when an opportunity is Closed/Won in Salesforce.

However, I am wondering if there's a way to include a link to the opportunity as part of the Apex class body.

Here's what I have so far:

public with sharing class SlackPublisher {
 
private static final String SLACK_URL = 'HIDDEN URL';
 
public class Oppty {
    @InvocableVariable(label='Opportunity Name')
    public String opptyName;
      @InvocableVariable(label='Opportunity Owner')
    public String opptyOwnerName;
    @InvocableVariable(label='Account Name')
    public String acctName;
    @InvocableVariable(label='Amount')
    public String amount;
}
 
@InvocableMethod(label='Post to Slack')
public static void postToSlack ( List<Oppty> opps ) {
    Oppty o = opps[0]; // bulkify the code later
    
    Map<String,Object> msg = new Map<String,Object>();
     msg.put('text','Deal ' + o.opptyName + ' was just Closed/Won' + ':champagne:' + '\n' + 'for a total of ' + '

Which sends a message to Slack like this:

Slack Notification Image

What I'm looking for is either a way to make the opptyName (Gary Test 1 - Gong) a hyperlink OR add the opportunity URL at the end.

+ o.amount + '\n' + ' Check out the details in the document links below'); msg.put('mrkdwn', true); String body = JSON.serialize(msg); System.enqueueJob(new QueueableSlackPost(SLACK_URL, 'POST', body)); } public class QueueableSlackPost implements System.Queueable, Database.AllowsCallouts { private final String url; private final String method; private final String body; public QueueableSlackPost(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); } } }

Which sends a message to Slack like this:

Slack Notification Image

What I'm looking for is either a way to make the opptyName (Gary Test 1 - Gong) a hyperlink OR add the opportunity URL at the end.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

囚我心虐我身 2025-01-16 07:29:17

查看 URL 类,特别是 getSalesforceBaseUrl、getOrgDomainUrl

Id i = '0060g00000zQO77AAG';
String href = URL.getSalesforceBaseUrl().toExternalForm() + '/' + i;
System.debug(href);
// https://redacted--sandbox.my.salesforce.com/0060g00000zQO77AAG

Check out the URL class, especially getSalesforceBaseUrl, getOrgDomainUrl.

Id i = '0060g00000zQO77AAG';
String href = URL.getSalesforceBaseUrl().toExternalForm() + '/' + i;
System.debug(href);
// https://redacted--sandbox.my.salesforce.com/0060g00000zQO77AAG
鸢与 2025-01-16 07:29:17

请尝试这样的事情
创建消息请求正文时
https://SalesforceBaseUrl.com 替换为您的销售人员基本 URL

[ URL.getSalesforceBaseUrl().toExternalForm() ]

    {
    "blocks": [
        {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": "Deal <https://SalesforceBaseUrl.com/opp.Id |Gary Test1 - Gong> was just Closed/Won \n for total $5,000"
            }
        }
    ]
}

将 在 slack 上给出以下输出 消息

如果您有任何问题,请告诉我

Please try something like this
while creating the message request body
replace the https://SalesforceBaseUrl.com with your salesforce base URL

[ URL.getSalesforceBaseUrl().toExternalForm() ]

    {
    "blocks": [
        {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": "Deal <https://SalesforceBaseUrl.com/opp.Id |Gary Test1 - Gong> was just Closed/Won \n for total $5,000"
            }
        }
    ]
}

Should give following output on slack message

Let me know if you have any questions

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文