从 Salesforce 中的 Apex 触发器向当前用户提供通知

发布于 2024-11-29 11:00:34 字数 449 浏览 0 评论 0原文

我正在尝试找出一种用户友好的方式从我的 Apex 代码向用户传递消息。我有一个触发器,它在插入/更新潜在客户后触发,然后过滤更新列表并触发 @future 方法,该方法将潜在客户数据推送到外部 Web 服务,并使用一些返回值更新转换后的帐户。

我想要执行以下操作(其中 X、Y 和 Z 是从 1 到 50 的任意数量的线索)

  • 通知用户转换线索 X、Y 和 Z 将被导出(我会在触发期间知道这一点)执行)。
  • 通知用户导出是否成功或失败(当 @future 方法运行时,X、Y 和 Z 中的每一个都将获知)。

将此信息传递回用户的推荐方法是什么?我宁愿使用电子邮件(因为这会触发每条记录一封电子邮件,这是相当垃圾邮件且令人不快)。还有其他方法可以将通知消息注入页面吗?我尝试过 ApexPages.addMessage() 但它似乎对我没有任何作用(没有错误,但也没有通知)。

I'm trying to figure out a user friendly way to pass messages to users from my Apex code. I have a trigger which fires after insert/update of a lead, which then filters the list of updates and triggers a @future method which pushes the lead data out to an external web service and updates the converted account with some of the returned values.

I'd like to do the following (where X, Y and Z are any number of leads from 1 to 50)

  • notify the user converting the leads that leads X, Y and Z will be exported (I'll know this during the trigger execution).
  • notify the user whether the export succeeded or failed (which will be known for each of X, Y and Z when the @future method runs).

What is the recommended way to pass this information back to the user? I'd prefer not to use email (as this would trigger one email per record, which is pretty spammy and unpleasant). Is there another way to inject notification messages into a page? I've tried ApexPages.addMessage() but it doesn't seem to do anything for me (no error, but no notice either).

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

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

发布评论

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

评论(1

栀梦 2024-12-06 11:00:34

当当前页面处于活动状态时,addMessage() 适用于 Visualforce 页面和标准页面,因此如果用户从按钮/VF 页面触发操作,则在触发器中使用此功能应该可以正常工作。但是,在您的 @future 方法中使用此方法不起作用,因为它在后台异步运行。

也许最好的解决方案是使用自定义消息对象,该对象具有修改时间的字段列表,并且可以查找适当的用户(或将他们用作所有者)。然后,您可以创建一个简单的 VF 页面和控制器,当查看该页面和控制器时,它会查询与当前用户相关的该对象中的记录,并提供删除它们的选项(您可以在从数据库中提取它们后自动删除它们,但您会面临以下风险:用户实际上没有注意到消息)。然后,您可以使用此页面并将其用作仪表板组件的一部分,因此无论用户何时查看其主页,他们都可以看到通知列表。

最后,另一种选择可能是利用 Chatter,通过将消息发送给用户,然后消息也会显示在摘要电子邮件等中。

addMessage() works with both Visualforce pages and standard pages when there's a current page active, so using this in the trigger should work fine if the user is firing the action from a button / VF page. Using this won't work from your @future method however because it runs asynchronously in the background.

Maybe the best solution would be to use a custom message object, which has a list of fields modified, when, and has a lookup to the appropriate user (or uses them as the owner). You could then create a simple VF page and controller which when viewed queries for records in that object related to the current user and provides an option to delete them (you could automatically delete them after pulling them from the DB but you run the risk of the user not actually noticing a message). You can then take this page and use it as part of a dashboard component, so anytime the user is viewing their Home page they could see a list of notifications.

Finally another option might be making use of Chatter, pumping the messages to the user via that which will then also show up in digest emails etc..

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