I'm trying to store a long JSON string as a Document. The problem is that when I download this doc and open it I see unreadable text with signs and strange characters. looks like I opened a binary file. This is my JS function on the VF page,where body is my string; what am I doing wrong?
function createDocument(body){
// console.log("body: " + body);
var document = new sforce.SObject('Document');
var now = new Date();
document.Name = now + '_DataStore.json';
document.Body = body;
document.FolderId = '005d0000000fLdI';
document.ContentType = 'application/json';
result = sforce.connection.create([document]);
if(!result[0].getBoolean("success")){
alert("Failed to create document");
}
else{
window.location.href='/'+result[0].id;
}
}