salesforce之chatter

本示例展示了如何使用 Salesforce 的 Chatter API 进行发帖操作,包括通过 Apex 类实现对 Chatter Group 的消息发布及直接针对用户的提及发帖。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://deferloader.blog.uhuru.co.jp/?p=2763

 //投稿処理
    private void doChatter(list<string> chatterMsgList){
        // ChatterGroup名指定
         // ChatterGroup取得
        //CollaborationGroup objCollaborationGroup = [select Id ,Name from CollaborationGroup where Name =: groupName limit 1];
        //string targetGroupId = objCollaborationGroup.Id;
        string targetGroupId = this.getGroupId();
        string message ='';
        for (String chatterMsg: chatterMsgList) {
            message +=  chatterMsg;
        }
        // フィードのINSERT
        FeedItem feed = new FeedItem();
        feed.parentId = targetGroupId;
        feed.body = message;
        insert feed;
    }


 public static void toChatter(String chatterMsg) {
        String communityId = null;
        ConnectApi.FeedType feedType = ConnectApi.FeedType.UserProfile;
        String userToMention = UserInfo.getUserId();
        String subjectId = userToMention;

        ConnectApi.MessageBodyInput messageInput = new ConnectApi.MessageBodyInput();
        messageInput.messageSegments = new List<ConnectApi.MessageSegmentInput>();
        // メンション
        ConnectApi.MentionSegmentInput mentionSegment = new ConnectApi.MentionSegmentInput();
        mentionSegment.id = userToMention;
        messageInput.messageSegments.add(mentionSegment);
        // 本文
        ConnectApi.TextSegmentInput textSegment = new ConnectApi.TextSegmentInput();
        textSegment.text = '\r\n';
        messageInput.messageSegments.add(textSegment);
        textSegment = new ConnectApi.TextSegmentInput();
        textSegment.text = chatterMsg;
        messageInput.messageSegments.add(textSegment);
        ConnectApi.FeedItemInput input = new ConnectApi.FeedItemInput();
        input.body = messageInput;
        // Chatter通知
        ConnectApi.FeedItem feedItemRep =
            ConnectApi.ChatterFeeds.postFeedItem(communityId, feedType, subjectId, input, null);
    }



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值