[SalesForce] Not able to update Rich text field with XML data

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..

Best Answer

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.

Related Topic