Hello all,
I was wondering, as community admin, if it's possible to convert an already-posted question to a post in Chatter Questions. We are trying to close the "open questions" and most of them are not even questions but have been posted as such. I have not been able to find any lead on that. Could somebody please point me into the right direction if the conversion is possible.
Thanks much!
Hello, Muhammad
Unfortunately, there is no native way to convert a Chatter post into a Chatter question :-(
However, there are a few workarounds that you can use:
Method 1: Copy and Paste the Post Text into a New Chatter Question
This is the simplest method but can be cumbersome if you have many posts to convert.
1. Open the Chatter post that needs to be converted.
2. Copy the text of the post.
3. Open a new Chatter question.
4. Paste the post text into the question field.
Method 2: Writing Code to Assist in Conversion
!!!
This method is risky because it deletes converted posts after conversion, so I strongly recommend testing it in a sandbox to avoid any issues later on.
!!!
For this method, add the tag " #convert" to the post and then execute the following code in the Developer Console's Anonymous Window:
// Declare variables
List<FeedItem> postsToDelete = new List<FeedItem>();
List<FeedItem> questionsToInsert = new List<FeedItem>();
// Get all Chatter TextPosts
List<FeedItem> textPosts = [SELECT Id, Body, ParentId FROM FeedItem WHERE Type = 'TextPost' AND ParentId != null];
// Loop through all Chatter TextPosts
for (FeedItem textPost : textPosts) {
// Check if the post's Body contains the '#convert' tag
if (textPost.Body != null && textPost.Body.contains('#convert')) {
// Remove the '#convert' tag and <p> tags from the Body using a regular expression
String cleanedBody = textPost.Body.replaceAll('(?i)#convert|<p>|</p>', '');
// Create a new Chatter Question
FeedItem question = new FeedItem(
Type = 'QuestionPost',
Title = 'Converted Question', // Set a default title or provide a meaningful title
Body = cleanedBody,
ParentId = textPost.ParentId // Assuming this is the correct relationship name for ParentId in your schema
// Add other necessary fields for the question
);
// Add the new Chatter Question to the list for insertion
questionsToInsert.add(question);
// Update the original Chatter TextPost to remove the '#convert' tag and <p> tags
textPost.Body = cleanedBody;
update textPost;
// Add the original Chatter TextPost to the list for deletion
postsToDelete.add(textPost);
}
}
// Insert the new Chatter Questions
insert questionsToInsert;
// Delete the original Chatter TextPosts
delete postsToDelete;
This code automates the process, and the converted questions will have the label "Converted Question".
I tested it in the Trailhead Playground, and everything works. Below are the results:
Before:
After:
I hope this solution will be helpful to you.
Respectfully,
Mykhailo from IBVCLOUD OÜ team