You need to sign in to do that
Don't have an account?
GerhardNewman2
How to encode a string with UTF-8
Some of my customers have foreign characters in their company name. For example "Hót Breád Bakéry"
I need to pass the company name to an external webservice as a string encoded in UTF-8.
Does anyone know how to encode the string? Sounds simple, but I can't find the solution.
Because I didn't know what I was doing my question is misleading. What I wanted to do was pass data using a soap call, where the callout xml is encoded in utf8. Running debug told me the headers were utf-8 so I thought it was an issue with some string text contained within the xml. My thinking was incorrect the string was fine, but the callout xml was not being encoded with utf8. Here is the solution in case anyone else gets stuck on this.
This class was mostly auto generated using salesforce's wsdl to apex.
The added code to force utf8 is inside SaveXML (where the callout is made):
request_x.inputHttpHeaders_x = new Map<String, String>();
request_x.inputHttpHeaders_x.put('charset', 'utf-8');
and this added to the end of the SaveXML_element (the request definition)
private Map<String, String> inputHttpHeaders_x = new Map<String, String>();