2

Created a trigger on FeedItem where it creates a new record on a custom object called Internal Request. I've mapped the Body of the Chatter post to the Description__c field in the Internal Request custom object. It is mapping correctly, except that it adds <p> before and after the body content of the chatter post into the Description__c field on the newly inserted Internal Request record.

Does anyone know why this is happening and how I can remove the <p>?

for(FeedItem cg : lGroupFeed){

                Ops_Priority_List__c i = new Ops_Priority_List__c(
                    OwnerId = mpostUserId.get(cg.Id),  
                    Description__c = cg.Body + '   ' + URL.getSalesforceBaseURL().toExternalForm() + '/_ui/core/chatter/groups/GroupProfilePage?g=0F93B0000004VGm&fld=' +cg.Id,   
                    Name = 'Questions from Chatter',   
                    Status__c = 'New', 
                    RecordTypeId = internalRequestQuestionRecordTypeId); 
                    newIRtoInsert.add(i); 
        }

Screenshot of the ChatterPost

Screenshot of new record inserted

2 Answers 2

3

If you want to strip all HTML tags, there is a method for that. Seems like the simplest solution here:

String description = '';
if (cg.Body != null) description += cg.Body.stripHtmlTags();
description += // build url here;
0
0

The reason those tags are included is because the post is created with Rich Text enabled. Chatter post relies on the HTML tags in the body to preserve the rich text info.

If you don't want to have the tags in your custom object, you can use the stripHtmlTags() function as Adrian suggested. But depends on what you do with the custom object, you might want to keep the tags if it will get rendered as html later.

You can also turn Rich Text off from the Settings so posts cannot be created with rich text info.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .