All Projects → forcedotcom → Connectapihelper

forcedotcom / Connectapihelper

Licence: bsd-3-clause
Helper class that makes it easier to post Chatter @-mentions, rich text, and inline images with Apex code.

Labels

Projects that are alternatives of or similar to Connectapihelper

Data Ingestion Platform
Stars: ✭ 39 (-45.83%)
Mutual labels:  apex
Apex Legends Internal
Simple Apex Legends esp source
Stars: ✭ 53 (-26.39%)
Mutual labels:  apex
Apexunit
ApexUnit is a powerful continuous integration tool for the Force.com platform
Stars: ✭ 69 (-4.17%)
Mutual labels:  apex
Purealoe Lwc
Sample application for Lightning Web Components on Salesforce Platform. Part of the sample gallery. Agriculture and retail use case. Get inspired and learn best practices.
Stars: ✭ 43 (-40.28%)
Mutual labels:  apex
Stripeforce
Stripe API Client Library for Force.com
Stars: ✭ 50 (-30.56%)
Mutual labels:  apex
Sobject Remote
JavaScript library to simplify CRUD DML operations with JavaScript Remoting on the force.com platform.
Stars: ✭ 57 (-20.83%)
Mutual labels:  apex
Objectmerge
Open-source solution for merging Salesforce objects and their related objects.
Stars: ✭ 35 (-51.39%)
Mutual labels:  apex
Apex Dml Manager
Enforces CRUD/FLS in the least disruptive way possible
Stars: ✭ 70 (-2.78%)
Mutual labels:  apex
Streams
Durable event pipelines.
Stars: ✭ 51 (-29.17%)
Mutual labels:  apex
Lwc Recipes
A collection of easy-to-digest code examples for Lightning Web Components on Salesforce Platform
Stars: ✭ 1,147 (+1493.06%)
Mutual labels:  apex
Gh Polls
Create a poll with gh-polls
Stars: ✭ 45 (-37.5%)
Mutual labels:  apex
Dg Net
Joint Discriminative and Generative Learning for Person Re-identification. CVPR'19 (Oral)
Stars: ✭ 1,042 (+1347.22%)
Mutual labels:  apex
Apex Domainbuilder
Framework to setup Apex test data in a highly flexible and readable way using the Test Data Builder pattern.
Stars: ✭ 61 (-15.28%)
Mutual labels:  apex
Forcedotcomsprintwall
An agile sprint wall built on the force.com platform with jQuery and Javascript Remoting
Stars: ✭ 42 (-41.67%)
Mutual labels:  apex
Rflib
Salesforce open source library with logging framework, trigger framework, feature switches, and advanced monitoring capabilities
Stars: ✭ 69 (-4.17%)
Mutual labels:  apex
Forcedotcom Enterprise Architecture
Force.com Enterprise Architecture - First Edition - Source Code
Stars: ✭ 35 (-51.39%)
Mutual labels:  apex
Wsdl2apex
Stars: ✭ 54 (-25%)
Mutual labels:  apex
Sfdc Convert Attachments To Chatter Files
📎 Easily migrate your Attachments to Salesforce Files.
Stars: ✭ 72 (+0%)
Mutual labels:  apex
Cinnamon
Cinnamon is a Force.com app that enables you to build and run Selenium tests to validate custom UI pages with Visualforce/Javascript in your Salesforce org.
Stars: ✭ 70 (-2.78%)
Mutual labels:  apex
Purealoe
Salesforce Sample App part of the sample gallery. Agriculture and retail use case. Get inspired and learn best practices.
Stars: ✭ 65 (-9.72%)
Mutual labels:  apex

ConnectApiHelper

ConnectApiHelper is an Apex class that makes it easier to do common operations with the classes in the ConnectApi namespace. It includes convenience methods to:

  • Post Chatter @-mentions with Apex code.
  • Post rich text, inline images, and record links with Apex code.
  • Take a feed item or comment body and return an input body that matches it (useful for either editing or re-posting).

Easier @-mentions

If 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:

ConnectApi.FeedItem fi = (ConnectApi.FeedItem) ConnectApiHelper.postFeedItemWithMentions(Network.getNetworkId(), 'me', 'Hey there {005D00000015tjz}, how are you?');

... instead of this:

ConnectApi.MessageBodyInput messageInput = new ConnectApi.MessageBodyInput();
messageInput.messageSegments = new List<ConnectApi.MessageSegmentInput>();

ConnectApi.TextSegmentInput textSegment = new ConnectApi.TextSegmentInput();
textSegment.text = 'Hey there ';
messageInput.messageSegments.add(textSegment);

ConnectApi.MentionSegmentInput mentionSegment = new ConnectApi.MentionSegmentInput();
mentionSegment.id = '005D00000015tjz'; // The ID of the user to mention.
messageInput.messageSegments.add(mentionSegment);

textSegment = new ConnectApi.TextSegmentInput();
textSegment.text = ', how are you?';
messageInput.messageSegments.add(textSegment);

ConnectApi.FeedItemInput input = new ConnectApi.FeedItemInput();
input.body = messageInput;
input.subjectId = 'me';

ConnectApi.FeedItem fi = ConnectApi.ChatterFeeds.postFeedElement(Network.getNetworkId(), input);

Streamlined rich text, inline images and record links

If you want to add rich text, inline images, or record links in your post, one line will do it:

ConnectApi.FeedItem fi = (ConnectApi.FeedItem) ConnectApiHelper.postFeedItemWithRichText(Network.getNetworkId(),
'me', 'Have you seen this <b>gorgeous</b> view? {img:069x00000000D7m:View of the Space Needle from our office.} \nBy the way, please check {record:01t3E000002GCm9QAG}');

... instead of this:

ConnectApi.MessageBodyInput messageInput = new ConnectApi.MessageBodyInput();
messageInput.messageSegments = new List<ConnectApi.MessageSegmentInput>();

ConnectApi.TextSegmentInput textSegment = new ConnectApi.TextSegmentInput();
textSegment.text = 'Have you seen this ';
messageInput.messageSegments.add(textSegment);

ConnectApi.MarkupBeginSegmentInput markupBeginSegment = new ConnectApi.MarkupBeginSegmentInput();
markupBeginSegment.markupType = ConnectApi.MarkupType.Bold;
messageInput.messageSegments.add(markupBeginSegment);

textSegment = new ConnectApi.TextSegmentInput();
textSegment.text = 'gorgeous';
messageInput.messageSegments.add(textSegment);

ConnectApi.MarkupEndSegmentInput markupEndSegment = new ConnectApi.MarkupEndSegmentInput();
markupEndSegment.markupType = ConnectApi.MarkupType.Bold;
messageInput.messageSegments.add(markupEndSegment);

textSegment = new ConnectApi.TextSegmentInput();
textSegment.text = ' view? ';
messageInput.messageSegments.add(textSegment);

ConnectApi.InlineImageSegmentInput inlineImageSegment = new ConnectApi.InlineImageSegmentInput();
inlineImageSegment.fileId = '069x00000000D7m';
inlineImageSegment.altText = 'View of the Space Needle from our office.';
messageInput.messageSegments.add(inlineImageSegment);

textSegment = new ConnectApi.TextSegmentInput();
textSegment.text = ' \nBy the way, please check ';
messageInput.messageSegments.add(textSegment);

ConnectApi.EntityLinkSegmentInput entityLinkSegment = new ConnectApi.EntityLinkSegmentInput();
entityLinkSegment.entityId = '01t3E000002GCm9QAG';
messageInput.messageSegments.add(entityLinkSegment);

ConnectApi.FeedItemInput input = new ConnectApi.FeedItemInput();
input.body = messageInput;
input.subjectId = 'me';

ConnectApi.FeedItem fi = ConnectApi.ChatterFeeds.postFeedElement(Network.getNetworkId(), input);

Installation

Just copy the ConnectApiHelper and ConnectApiHelperTest classes to your Salesforce org. If you use Salesforce DX, you can clone this repo and develop using your preferred IDE, source control system, and scratch orgs.

Usage

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.

For creating input bodies from output bodies, the methods are ConnectApiHelper.createFeedItemInputFromBody and ConnectApiHelper.createCommentInputFromBody.

Salesforce API Versions

If 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.

We've provided variants of ConnectApiHelper so that you can use it with earlier Salesforce API versions:

API Version ConnectApiHelper location Limitations
43.0 and higher default
36.0-42.0 v36-v42 Record links not supported
35.0 v35 Same as above
32.0-34.0 v32-v34 Same as above, and rich text not supported
31.0 and earlier v31AndEarlier Same as above
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].