function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Tiwari VedantTiwari Vedant 

We are trying to show '<' and '>' character in feeditem body. But we are getting invalid markup error while inserting the feeditem.body

We are trying to show '<' and '>' character in feeditem body. But we are getting invalid markup error while inserting the feeditem.body.

String is <test>

public static void createRFAFeedEntry(List<Request_for_Assistance__c> newRFA){
        List<FeedItem> feedItemsList = new List<FeedItem>();
        for(Request_for_Assistance__c req : newRFA) {
            if(req.recordtypeid==JIRA_RECORD_TYPE_ID){
                FeedItem post = new FeedItem();
                FeedItem post_sec = new FeedItem();
                post.ParentId = req.id;
                post.createdById = req.createdbyid;
                String fullFileURL = URL.getSalesforceBaseUrl().toExternalForm()+'/'+ req.id;
                String stringURL  = '<a href='+fullFileURL+' >'+req.Name+'</a>';
                post.LinkUrl = fullFileURL ;
                post.Title = 'Created '+req.Name;
                post.Visibility = 'InternalUsers';
                
                               /**********************/
               
               String summ=String.valueof(req.Summary__c);
               String escapeString = summ.escapeHtml3();
               string escapeString1=escapeString.unescapeHtml3();
               /* String sum1 =String.valueof(req.Summary__c) ;
                String target1 = '<';
                String target2='>';
                String replacement1 = '{';
                String replacement2 = '}';
                String sum2 = sum1.replace(target1, replacement1);
                //system.debug('test string***'+sum2);
                String summary = sum2.replace(target2, replacement2);
                //system.debug('test string***'+summary);
                
                String pdd1 =String.valueof(req.Problem_Description_and_Definition__c);
                String target11 = '<';
                String target21='>';
                String pdd2 = pdd1.replace(target11, replacement1);
                //system.debug('test string***'+pdd2);
                String pdd = pdd2.replace(target21, replacement2);
                //system.debug('test string***'+summary);
                */
               /******************/   
                //post.Body =  'Created Date - '+req.CreatedDate+'\nSummary - '+req.Summary__c +'\nProblem Description and Definition - '+req.Problem_Description_and_Definition__c;
              
              post.Body =  'Created Date - '+req.CreatedDate+'\nSummary - '+ escapeString1 +'\nProblem Description and Definition - '+req.Problem_Description_and_Definition__c;
                
               feedItemsList.add(post);
               // feedItemsList.add(post); 
            }           
        }
        System.debug('feeditemlist--'+feedItemsList);
        if(!feedItemsList.isEmpty())
        insert feedItemsList;
        
    }
Insert failed. First exception on row 0; first error: INVALID_MARKUP, Error while parsing Rich Text Content: Unsupported HTML tag or attribute encountered.

Please help.
Jonathan A FoxJonathan A Fox
Try '&gt;' and '&lt;' special character codes and see if that makes a difference.
Tiwari VedantTiwari Vedant
Hi Jonathan,

Thanks for the reply. 
We are using escapehtml3() method to esacpe '<' and '>' which converts it to &gt; and &lt. Then we are unescaping it by using unescapehtml3() method as we want to show the exact '<' and '>' on UI. But we are still geting an error while inserting on feeditem.body.

Thanks,
Vedant
Jonathan A FoxJonathan A Fox
It might be worth looking at your markup:

Rich text supports the following HTML tags:
<p>, <b>, <code>, <i>, <u>, <s>, <ul>, <ol>, <li>, <img>

Though the <br> tag isn’t supported, you can use <p>&nbsp;</p> to create lines.
Olavo AlexandrinoOlavo Alexandrino
A workaround that I di

for saving

content = content.escapeHtml4();

FeedItem feedItem = new FeedItem(
ParentId = parentId,
Body = content,
IsRichText = true
);
insert feedItem;

for getting...

for (FeedItem item : feedItemList)
{
item.Body = item.Body.unescapeHtml4();
}

for displaying...

<lightning:formattedRichText disableLinkify="true" value="{!v.feedItem.Body}"/>