java 以编程方式将文件上传到 SalesForce
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15830460/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
upload a file to SalesForce programmatically
提问by Ravi Kumar
I build a flow which create a case in a salesforce. Now, I am trying to upload a file to that case programmatically. Basically the client uploads the file manually in the server. now the question is how could I upload it by java rest based web service. it's good to have any links which describe about this topic.
我建立了一个流程,在销售队伍中创建了一个案例。现在,我正在尝试以编程方式将文件上传到该案例。基本上客户端在服务器中手动上传文件。现在的问题是我如何通过基于 java rest 的 Web 服务上传它。最好有任何描述此主题的链接。
采纳答案by Shreyos Adikari
First try to read the documents below:
See the following:
http://www.salesforce.com/in/?ir=1
API doc:
http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_document.htm
Examples:
http://login.salesforce.com/help/doc/en/fields_useful_field_validation_formulas.htm
首先尝试阅读以下文档:
请参阅以下内容:
http : //www.salesforce.com/in/?
ir =1 API doc:
http : //www.salesforce.com/us/developer/docs/api/Content /sforce_api_objects_document.htm
示例:http : //login.salesforce.com/help/doc/en/fields_useful_field_validation_formulas.htm
The following code allows you to upload a physical file to Salesforce.com and attach it to a record.
Code:
以下代码允许您将物理文件上传到 Salesforce.com 并将其附加到记录。
代码:
try {
File f = new File("c:\java\test.docx");
InputStream is = new FileInputStream(f);
byte[] inbuff = new byte[(int)f.length()];
is.read(inbuff);
Attachment attach = new Attachment();
attach.setBody(inbuff);
attach.setName("test.docx");
attach.setIsPrivate(false);
// attach to an object in SFDC
attach.setParentId("a0f600000008Q4f");
SaveResult sr = binding.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());
}
} catch (FileNotFoundException fnf) {
System.out.println("File Not Found: " +fnf.getMessage());
} catch (IOException io) {
System.out.println("IO: " +io.getMessage());
}
Please try this and let me know in case of any concern.
请试试这个,如果有任何问题,请告诉我。
回答by Vahan
Previous answer gave API doc for Document instead of Attachment. API Doc for Attachment is: http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_attachment.htm
先前的答案为文档而不是附件提供了 API 文档。附件的 API 文档是:http: //www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_attachment.htm