{"id":28829213,"url":"https://github.com/forcedotcom/connectapihelper","last_synced_at":"2026-02-01T23:31:27.707Z","repository":{"id":13517583,"uuid":"16208666","full_name":"forcedotcom/ConnectApiHelper","owner":"forcedotcom","description":"Helper class that makes it easier to post Chatter @-mentions, rich text, and inline images with Apex code.","archived":false,"fork":false,"pushed_at":"2023-09-14T17:00:34.000Z","size":51,"stargazers_count":101,"open_issues_count":12,"forks_count":82,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-06-19T05:13:56.797Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Apex","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/forcedotcom.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":"SECURITY.md","support":null}},"created_at":"2014-01-24T15:41:37.000Z","updated_at":"2025-06-09T12:50:37.000Z","dependencies_parsed_at":"2022-09-05T02:50:36.200Z","dependency_job_id":null,"html_url":"https://github.com/forcedotcom/ConnectApiHelper","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/forcedotcom/ConnectApiHelper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/forcedotcom%2FConnectApiHelper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/forcedotcom%2FConnectApiHelper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/forcedotcom%2FConnectApiHelper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/forcedotcom%2FConnectApiHelper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/forcedotcom","download_url":"https://codeload.github.com/forcedotcom/ConnectApiHelper/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/forcedotcom%2FConnectApiHelper/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28994918,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-01T23:10:54.274Z","status":"ssl_error","status_checked_at":"2026-02-01T23:10:47.298Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-19T05:12:17.132Z","updated_at":"2026-02-01T23:31:27.702Z","avatar_url":"https://github.com/forcedotcom.png","language":"Apex","funding_links":[],"categories":[],"sub_categories":[],"readme":"ConnectApiHelper\n================\n\n`ConnectApiHelper` is an Apex class that makes it easier to do common operations with the classes in the [ConnectApi namespace](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_connect_api.htm). It includes convenience methods to:\n\n* Post Chatter @-mentions with Apex code.\n* Post rich text, inline images, and record links with Apex code.\n* Take a feed item or comment body and return an input body that matches it (useful for either editing or re-posting).\n\nEasier @-mentions\n-----------------\nIf you want to mention someone in a post that says: *Hey there @Jane Doe, how are you?*, you can do it in one line like this:\n\n    ConnectApi.FeedItem fi = (ConnectApi.FeedItem) ConnectApiHelper.postFeedItemWithMentions(Network.getNetworkId(), 'me', 'Hey there {005D00000015tjz}, how are you?');\n\n... instead of this:\n\n    ConnectApi.MessageBodyInput messageInput = new ConnectApi.MessageBodyInput();\n    messageInput.messageSegments = new List\u003cConnectApi.MessageSegmentInput\u003e();\n\n    ConnectApi.TextSegmentInput textSegment = new ConnectApi.TextSegmentInput();\n    textSegment.text = 'Hey there ';\n    messageInput.messageSegments.add(textSegment);\n\n    ConnectApi.MentionSegmentInput mentionSegment = new ConnectApi.MentionSegmentInput();\n    mentionSegment.id = '005D00000015tjz'; // The ID of the user to mention.\n    messageInput.messageSegments.add(mentionSegment);\n\n    textSegment = new ConnectApi.TextSegmentInput();\n    textSegment.text = ', how are you?';\n    messageInput.messageSegments.add(textSegment);\n\n    ConnectApi.FeedItemInput input = new ConnectApi.FeedItemInput();\n    input.body = messageInput;\n    input.subjectId = 'me';\n\n    ConnectApi.FeedItem fi = ConnectApi.ChatterFeeds.postFeedElement(Network.getNetworkId(), input);\n\nStreamlined rich text, inline images and record links\n-----------------------------------------------------\nIf you want to add rich text, inline images, or record links in your post, one line will do it:\n\n    ConnectApi.FeedItem fi = (ConnectApi.FeedItem) ConnectApiHelper.postFeedItemWithRichText(Network.getNetworkId(),\n    'me', 'Have you seen this \u003cb\u003egorgeous\u003c/b\u003e view? {img:069x00000000D7m:View of the Space Needle from our office.} \\nBy the way, please check {record:01t3E000002GCm9QAG}');\n\n... instead of this:\n\n    ConnectApi.MessageBodyInput messageInput = new ConnectApi.MessageBodyInput();\n    messageInput.messageSegments = new List\u003cConnectApi.MessageSegmentInput\u003e();\n\n    ConnectApi.TextSegmentInput textSegment = new ConnectApi.TextSegmentInput();\n    textSegment.text = 'Have you seen this ';\n    messageInput.messageSegments.add(textSegment);\n\n    ConnectApi.MarkupBeginSegmentInput markupBeginSegment = new ConnectApi.MarkupBeginSegmentInput();\n    markupBeginSegment.markupType = ConnectApi.MarkupType.Bold;\n    messageInput.messageSegments.add(markupBeginSegment);\n\n    textSegment = new ConnectApi.TextSegmentInput();\n    textSegment.text = 'gorgeous';\n    messageInput.messageSegments.add(textSegment);\n\n    ConnectApi.MarkupEndSegmentInput markupEndSegment = new ConnectApi.MarkupEndSegmentInput();\n    markupEndSegment.markupType = ConnectApi.MarkupType.Bold;\n    messageInput.messageSegments.add(markupEndSegment);\n\n    textSegment = new ConnectApi.TextSegmentInput();\n    textSegment.text = ' view? ';\n    messageInput.messageSegments.add(textSegment);\n\n    ConnectApi.InlineImageSegmentInput inlineImageSegment = new ConnectApi.InlineImageSegmentInput();\n    inlineImageSegment.fileId = '069x00000000D7m';\n    inlineImageSegment.altText = 'View of the Space Needle from our office.';\n    messageInput.messageSegments.add(inlineImageSegment);\n\n    textSegment = new ConnectApi.TextSegmentInput();\n    textSegment.text = ' \\nBy the way, please check ';\n    messageInput.messageSegments.add(textSegment);\n\n    ConnectApi.EntityLinkSegmentInput entityLinkSegment = new ConnectApi.EntityLinkSegmentInput();\n    entityLinkSegment.entityId = '01t3E000002GCm9QAG';\n    messageInput.messageSegments.add(entityLinkSegment);\n\n    ConnectApi.FeedItemInput input = new ConnectApi.FeedItemInput();\n    input.body = messageInput;\n    input.subjectId = 'me';\n\n    ConnectApi.FeedItem fi = ConnectApi.ChatterFeeds.postFeedElement(Network.getNetworkId(), input);\n\nInstallation\n------------\n\nJust copy the [ConnectApiHelper](force-app/main/default/classes/ConnectApiHelper.cls) and [ConnectApiHelperTest](force-app/main/default/classes/ConnectApiHelperTest.cls) classes to your Salesforce org. If you use [Salesforce DX](https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_intro.htm), you can clone this repo and develop using your preferred IDE, source control system, and scratch orgs. \n\nUsage\n-----\n\n For @-mentions, the methods to use are `ConnectApiHelper.postFeedItemWithMentions` and `ConnectApiHelper.postCommentWithMentions` and the parameters and formatting syntax are described in the method comments. To include rich text and inline images as well (starting in version 35.0), the method to use is `ConnectApiHelper.postFeedItemWithRichText`.  You can also refer to the `ConnectApiHelperTest` class for more examples.\n\nFor creating input bodies from output bodies, the methods are `ConnectApiHelper.createFeedItemInputFromBody` and `ConnectApiHelper.createCommentInputFromBody`.\n\nSalesforce API Versions\n-----------------------\n\nIf you need to use an earlier version of the Salesforce API, the current `ConnectApiHelper` class may not compile, because the methods being called may not be available in the earlier version. \n\nWe've provided variants of `ConnectApiHelper` so that you can use it with earlier Salesforce API versions:\n\n| API Version      | ConnectApiHelper location                 | Limitations                                |\n|------------------|-------------------------------------------|--------------------------------------------|\n| 43.0 and higher  | [default](force-app/main/default/classes) |                                            |\n| 36.0-42.0        | [v36-v42](v36-v42)                        | Record links not supported                 |\n| 35.0             | [v35](v35)                                | Same as above                              |\n| 32.0-34.0        | [v32-v34](v32-v34)                        | Same as above, and rich text not supported |\n| 31.0 and earlier | [v31AndEarlier](v31AndEarlier)            | Same as above                              |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fforcedotcom%2Fconnectapihelper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fforcedotcom%2Fconnectapihelper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fforcedotcom%2Fconnectapihelper/lists"}