You need to sign in to do that
Don't have an account?
Ollie.ax81
INVALID_CROSS_REFERENCE_KEY
I am trying to add a document to a document folder with the following code, and I am calling this method from a JUnit test script that is passing in hard coded values and I am getting
error.getStatusCode() = INVALID_CROSS_REFERENCE_KEY
I obtained the authorId and folderId's from a view source of the Web Pages associated with the folder where I want to create the document. I have already created a folder on salesforce using a similar method called CreateFolder().
I cannot find a reference for this status code in the documentation or in this forum.
public String CreateDocument(String docName, File doc, String description, ID authorId, ID folderId) {
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;
}
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);
for (int i = 0; i < sr.length; i++) {
SaveResult result = sr[i];
if (result.isSuccess()){
retStatus = "Success Created Document " + docName;
} else {
Error[] ers = (Error[]) result.getErrors();
retStatus = "Error:";
for (int j = 0; j < ers.length; j++) {
Error error = ers[j];
retStatus += error.getMessage() + ";";
System.out.println("error.getStatusCode():" + error.getStatusCode());
echo(retStatus);
}
}
}
}
catch (UnexpectedErrorFault uef) {
echo(uef.getExceptionMessage());
}
catch (Exception ex) {
retStatus = "\nFailed to create folder, " + docName + ", error message was: \n"
+ ex.getMessage();
echo(retStatus);
}
return retStatus;
}
error.getStatusCode() = INVALID_CROSS_REFERENCE_KEY
I obtained the authorId and folderId's from a view source of the Web Pages associated with the folder where I want to create the document. I have already created a folder on salesforce using a similar method called CreateFolder().
I cannot find a reference for this status code in the documentation or in this forum.
public String CreateDocument(String docName, File doc, String description, ID authorId, ID folderId) {
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;
}
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);
for (int i = 0; i < sr.length; i++) {
SaveResult result = sr[i];
if (result.isSuccess()){
retStatus = "Success Created Document " + docName;
} else {
Error[] ers = (Error[]) result.getErrors();
retStatus = "Error:";
for (int j = 0; j < ers.length; j++) {
Error error = ers[j];
retStatus += error.getMessage() + ";";
System.out.println("error.getStatusCode():" + error.getStatusCode());
echo(retStatus);
}
}
}
}
catch (UnexpectedErrorFault uef) {
echo(uef.getExceptionMessage());
}
catch (Exception ex) {
retStatus = "\nFailed to create folder, " + docName + ", error message was: \n"
+ ex.getMessage();
echo(retStatus);
}
return retStatus;
}
Hi Ollie,
This error is typically associated with a deleted object. To be sure the folder is not deleted, get it's id using the API first.
hello, i have got 15 digit ID but where can i geet 18 digit ID..?