I’m running into a problem on a specific customer’s org when attempting to get the HTML from a custom object’s standard ‘new’ page layout.
String objPrefix = My_Object__c.SObjectType.getDescribe().getKeyPrefix(); PageReference page = new PageReference('/' + objPrefix + '/e?nooverride=1'); Blob b = page.getContent(); String html = b.toString();
Using the above code results in
BLOB is not a valid UTF-8 stringwhen attempting to use the
This code is running in a managed package and has worked successfully in many other orgs.
I know that
Blob.toString()method is only supported for UTF-8 encoded strings, but shouldn’t all VisualForce pages be encoded as UTF-8?
For shits and giggles you can try demoting it to ASCII before it gets to the page:
b = EncodingUtil.urlEncode(b, 'ASCII'); b = EncodingUtil.urlDecode(b, 'ASCII');
Or something elsewhere in your code is trying to stuff binary data into a string. Can happen in a few cases when trying to output:
Where’s the rest of your class? Nothing trying to dump
outputText into a page with funny
Worth noting NA0 (ssl.salesforce.com) is a special pod that does ISO-8559-1 only. Worth raising a case to Salesforce if this is inconsistent with behaviour in other pods.
You can determine the character set for your organization by doing a global describe and inspecting the encoding value returned.