Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added create functions to allow batch processing #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 39 additions & 4 deletions force-app/main/default/classes/ConnectApiHelper.cls
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,21 @@ global class ConnectApiHelper {
* @return The posted feed item.
*/
public static ConnectApi.FeedElement postFeedItemWithMentions(String communityId, String subjectId, String textWithMentions) {
return postFeedItemWithSpecialFormatting(communityId, createFeedItemWithMentions(subjectId, textWithMentions));
}

return postFeedItemWithSpecialFormatting(communityId, subjectId, textWithMentions, 'textWithMentions');
/**
* create a feed item with @-mentions using an @-mention formatting syntax.
*
* @param subjectId The parent of the post. Can be a user ID, a group ID, or a record ID.
* @param textWithMentions The text of the post. You can @-mention a user or group by using
* the syntax {ID}, for example: 'Hello {005x0000000URNP}, have you
* seen the group {0F9x00000000D7m}?' Links and hashtags will be
* automatically parsed if provided.
* @return The feed item input that can be posted.
*/
public static ConnectApi.FeedItemInput createFeedItemWithMentions(String subjectId, String textWithMentions) {
return createFeedItemWithSpecialFormatting(subjectId, textWithMentions, 'textWithMentions');
}

/**
Expand All @@ -92,10 +105,32 @@ global class ConnectApiHelper {
* @return The posted feed item.
*/
public static ConnectApi.FeedElement postFeedItemWithRichText(String communityId, String subjectId, String textWithMentionsAndRichText) {
return postFeedItemWithSpecialFormatting(communityId, subjectId, textWithMentionsAndRichText, 'textWithMentionsAndRichText');
return postFeedItemWithSpecialFormatting(communityId, createFeedItemWithRichText(subjectId, textWithMentionsAndRichText));
}

/**
* create a feed item with rich text using HTML tags and inline image formatting syntax.
*
* @param subjectId The parent of the post. Can be a user ID, a group ID, or a record ID.
* @param textWithMentionsAndRichText The text of the post. You can @-mention a
* user or group by using the syntax {ID}, for example:
* 'Hello {005x0000000URNP}, have you seen the group {0F9x00000000D7m}?'
* You can include rich text by using supported HTML tags:
* <b>, <i>, <u>, <s>, <ul>, <ol>, <li>, <p>, <code>.
* You can include an inline image by using the syntax {img:ID} or
* {img:ID:alt text}, for example: 'Have you seen this gorgeous view?
* {img:069x00000000D7m:View of the Space Needle from our office.}?'
* Links and hashtags will be automatically parsed if provided.
* @return The feed item input that can be posted.
*/
public static ConnectApi.FeedItemInput createFeedItemWithRichText(String subjectId, String textWithMentionsAndRichText) {
return createFeedItemWithSpecialFormatting(subjectId, textWithMentionsAndRichText, 'textWithMentionsAndRichText');
}

private static ConnectApi.FeedElement postFeedItemWithSpecialFormatting(String communityId, String subjectId, String formattedText, String textParameterName) {
private static ConnectApi.FeedElement postFeedItemWithSpecialFormatting(String communityId, ConnectApi.FeedItemInput input) {
return ConnectApi.ChatterFeeds.postFeedElement(communityId, input);
}
private static ConnectApi.FeedItemInput createFeedItemWithSpecialFormatting(String subjectId, String formattedText, String textParameterName) {
if (formattedText == null || formattedText.trim().length() == 0) {
throw new InvalidParameterException('The ' + textParameterName + ' parameter must be non-empty.');
}
Expand All @@ -107,7 +142,7 @@ global class ConnectApiHelper {
input.body = messageInput;
input.subjectId = subjectId;

return ConnectApi.ChatterFeeds.postFeedElement(communityId, input);
return input;
}

/**
Expand Down