我在 mule 中构建了一个流程,该流程使用“Salesforce”连接器在 Salesforce 中创建了一个案例。现在我需要使用相同的 mule 流程将文件上传到该案例。这可以通过以下代码以编程方式完成:
尝试 {
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());
}
但是为了简单起见,是否有任何骡子连接器可以自动完成所有这些并将文件附加到特定创建的案例中。