有没有办法在 Salesforce 的 apex 类主体中创建超链接?
我正在使用 这个< /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 发送一条消息,如下所示:
什么我正在寻找一种使 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:
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:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看 URL 类,特别是
getSalesforceBaseUrl、getOrgDomainUrl
。Check out the URL class, especially
getSalesforceBaseUrl, getOrgDomainUrl
.请尝试这样的事情
创建消息请求正文时
https://SalesforceBaseUrl.com 替换为您的销售人员基本 URL
[ URL.getSalesforceBaseUrl().toExternalForm() ]
将 在 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() ]
Should give following output on slack message
Let me know if you have any questions