0

We use Perl Salesforce library WWW::Salesforce to connect our web shop via SOAP API with Salesforce and Financial Force.

For invoices we send a string with HTML code to a richtext field in c2g__InvoiceDescription__c. The string and HTML special chars like < > are not encoded in any way. This worked until some days ago. We didn't change our Perl code, but on updating we get error message:

unable to update c2g__InvoiceDescription__c for a0z2s000002AW0PAAW: Unexpected element {}table during simple type deserialization

I can set the API version in WWW::Salesforce but error seems to be independet from version.

Richtext field definition for WWW::Salesforce is

WWW::Salesforce::Constants->register_type( 'c2g__InvoiceDescription__c', 'Items__c', 'xsd:string' );

For updating invoices upsert method of API is used which gets a hash with fields and values:

{
    'id' => $salesforce_id,
    'Items__c' => '<table>...</table>',
}

What is the correct way to send HTML code via SOAP API to a richtext field? A simple example for sending HTML via SOAP API would be very appreciated (doesn't have to be Perl)

1 Answer 1

0

The SOAP API uses XML, which is a variant of SGML (the Standardized General Markup Language), which is also used by HTML. As such, when you place unsafe characters, which are &, <, >, and ", inside a string literally and it's later formatted into XML, you end up with something like:

<Items__c>
  <table>
    ...
  </table>
</Items__c>

This causes the XML to fail to parse with errors like Unexpected element {}table during simple type deserialization. In order to fix it, you need to escape these special characters. The easiest way would probably be with HTML::Entities:

use HTML::Entities;
...
'Items__c' => encode_entities('<table>...</table>');

Technically, the WWW::Salesforce client should do this for you automatically. I'm going to check the source and find out if you're just missing something, or if it's a bug, but either way, you now have a solution to your problem.

2
  • thanks, I already thought that encoding is needed, but I wonder why it worked without until last week.
    – Obi_77
    Jul 12, 2021 at 20:35
  • @Obi_77 Yeah, WWW::Salesforce hasn't been updated in about four years. Not sure what to say. Are you working with anyone else on your project? Maybe try a git blame?
    – sfdcfox
    Jul 12, 2021 at 21:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.