2

I have created a custom field(Rich Text field) with the Case object and am trying to update that fiekd value with XML data while clicking a button.

If I hard code the value like

CurrentCase.XML_Field__c='value has been hard coded for testing purpose';

This hard coded value is getting updated properly. But if I give the xml variable it is not getting updated.

Lets say my xml string value is -

<?xml version="1.0" encoding="utf-8"?>
 ...........
 ...........

and it has 298 characters. If I assign this variable to my RichTextField it is not getting updated and not throwing any error as well.

Any help would be appreciated...

Thanks

Update:- If I remove these <,>,</,<?,?> symbols from the xml string and hard coding the rest of the entire string(whatever may be the length) am able to update my rich text field. Whether these symbols are the reason xml is not getting updated..

4
  • Chitra, Are you trying to update it through UI or Apex coding?
    – Bforce
    Commented Jul 2, 2014 at 16:53
  • These fields only hold limited HTML content, not XML. Are you trying to store unsupported elements, such as HTML or BODY tags?
    – sfdcfox
    Commented Jul 2, 2014 at 18:37
  • @ Baskaran, Yes am trying to update it through code. My apex class contains the code to update this rich text field. pathValues= getPathXML(); CurrentCase.Path_XML__c=pathValues; this path_XML__c needs to be updated... Commented Jul 3, 2014 at 7:49
  • @ sfdcfox, The xml string starts with <?xml version="1.0" encoding="utf-8"?><case id=..............><validation>....</validation>...<cause>....</cause></case> My xml string contains only these kind of tags not any HTML tag like HTML or BODY.. Commented Jul 3, 2014 at 7:57

3 Answers 3

3

RichTextArea strips out certain tags from the markup and so this is why your data isn't stored correctly.

Test__c cr = new Test__c(id='a0H11000008jpJD');
cr.xml__c = '<?xml version="1.0" encoding="utf-8"?><bob>Hello World</bob>';
update cr;

cr = [select xml__c from Test__c where id='a0H11000008jpJD'];
system.debug(cr.xml__c);

debug = 'Hello World'.

If you change to a TextArea field type then the data is correctly stored. debug now shows

'<?xml version="1.0" encoding="utf-8"?><bob>Hello World</bob>'

My suggestion is change the fieldtype to TextArea and this should store the data correctly.

1
  • Yes it is working fine now...I have just changed the field type from Rich Text to Text Area(Long)..Thank you Richard. Commented Jul 3, 2014 at 10:35
1

A rich text area only stores "HTML" content, not "XML" content. You cannot freely store any tags you wish, only those that are allowed in HTML that cannot cause potential threats (e.g. you cannot store script tags, because this could be used for XSS attacks) or are not useful in a document context (e.g. the head tag is used for header data).

While I cannot seem to find a list of elements which are allowed, you should assume that the only legal elements are those that appear on the toolbar when you try manually editing a record that has a rich text area. The system automatically handles situations such as elements not closed, or wrapped incorrectly, etc, in a predefined manner that cannot be altered.

If you need to store any arbitrary XML, use either a text area or long text area, depending on the storage requirements. If you wish to present formatted text to a user, use the rich text area, and use only basic HTML.

0

Changing the field type from Rich Text to Long Text solved my problem.

Thanks to everyone..

You must log in to answer this question.

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