function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ollie.ax81Ollie.ax81 

INVALID_TYPE_ON_FIELD_IN_RECORD Body: value not of required type: 115

The log shows:

The new server url is: https://na1-api.salesforce.com/services/Soap/c/3.0
SalesForceContentManager:
Getting server's timestamp...
SalesForceContentManager:Time stamp on server: May 18, 2005 4:30:54 PM GMT
error.getStatusCode():INVALID_TYPE_ON_FIELD_IN_RECORD
SalesForceContentManager:Error:Body: value not of required type: 115;


The head of one of the applicable .java source files is:

/**
* Document.java
*
* This file was auto-generated from WSDL
* by the Apache Axis WSDL2Java emitter.
*/

package com.sforce.soap.enterprise.sobject;

public class Document extends com.sforce.soap.enterprise.sobject.SObject implements java.io.Serializable {
private com.sforce.soap.enterprise.ID authorId;
private byte[] body;

...

My code accesses and binds ok and creates a Document Folder ok but when I use the following code to try to upload a document into a folder I get an error that contains the subject of this message.

my code looks like:

public String CreateDocument(String docName, File doc, String description,
ID authorId, ID folderId) {
echo("CreateDocument");
echo("docName=" + docName);
echo("File doc=" + doc.toString());
echo("Description=" + description);
echo("authorId=" + authorId.getValue());
echo("folderId=" + folderId.getValue());

String retStatus = "Success";
int fileLength = (int) doc.length();
byte[] body = new byte[fileLength];

//Verify that we are already authenticated, if not
//call the login function to do so
if (!loggedIn) {
if (!login()) {
return "Bad SalesForce Login";
}
}
try {
FileInputStream fis = new FileInputStream(doc);
fileLength = fis.read(body);
} catch (FileNotFoundException e) {
retStatus = "Error Failed to CreateDocument:"
+ e.getLocalizedMessage();
e.printStackTrace();
return retStatus;
} catch (IOException e1) {
retStatus = "Error Failed to CreateDocument:"
+ e1.getLocalizedMessage();
e1.printStackTrace();
return retStatus;
}

if (authorId == null) {
//default to current user
authorId = this.loginResult.getUserId();
}

try {
Document document;
SObject[] accs = new SObject[1];
document = new Document();

document.setName(docName);
document.setBody(body);
document.setDescription(description);
document.setAuthorId(authorId);
document.setFolderId(folderId);

accs[0] = document;

//create the object(s) by sending the array to the web service
SaveResult[] sr = binding.create(accs);
...

This code was working at one time and the authorId and folderId are valid, and the body is a byte[] that contains the document, albeit not base64 encoded...

Do I need to base64 encode the body?
Do I need to update my sforce sources?

Message Edited by Ollie on 05-18-2005 10:18 AM

Ollie.ax81Ollie.ax81
Using Java and Axis 1.1

Ok I downloaded v 5.0 and rebuilt everything and now I am getting through to

Document document;
SObject[] accs = new SObject[1];
document = new Document();
document.setName(docName);
document.setBody(body);
document.setDescription(description);
document.setAuthorId(authorId);
document.setFolderId(folderId);

accs[0] = document;
SaveResult[] sr = binding.create(accs);
sr[0] =
.statusCode = "_value_=INVALID_TYPE_ON_FIELD_IN_RECORD "
.message = "Body: value not of required type: 62"

This code was working in version 3.0

And I read that Axis is supposed to handle the Base64 encoding.

A Java/Axis example might help?

Message Edited by Ollie on 05-19-2005 11:02 AM

Ollie.ax81Ollie.ax81
I have read and compared my code with DevAngel's code that follows, and except that it is for an Attachment object instead of a Document Object and a couple of different fields, it looks to be the same.

File f = new File("test.doc");
InputStream is = new FileInputStream(f);
byte[] inbuff = new byte[(int)f.length()];

is.read(inbuff);
Attachment attach = new Attachment();
attach.setBody(inbuff);
//Do not attempt to set body length, this calculated
//be salesforce.com
//attach.setBodyLength(new Integer(inbuff.length));
attach.setName("text.doc");
ID parentId = new ID();
parentId.setValue("00330000006ZpSZ");
attach.setParentId(parentId);
SoapBindingStub b = loginEnterprise("mobile2@user.com", "pass");
SaveResult sr = b.create(new com.sforce.soap.enterprise.sobject.SObject[] {attach})[0];
if (sr.isSuccess())
System.out.println("Successfully added attachment.");
else
System.out.println("Error adding attachment: " + sr.getErrors(0).getMessage());
}
Ollie.ax81Ollie.ax81
The body was null because of an exception in the Document SObject caused by an errant log attempt.

See the other thread RE Error Adding Document.