使用连接器将文件上载到salesforce

我在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()); } 

但为了简单起见,是否有任何mule连接器自动完成所有这些并将文件附加到特定创建的案例。

是的,您可以使用Salesforce云连接器。 例:

     #[payload] test.docx #[message.inboundProperties['mysfdcparentid']]    

在示例中,我将sobject类型设置为“Attachment”。

body元素是文件本身。 请注意,连接器将为您处理base64编码,您只需要为其提供一个字节数组。 如果您正在使用File,则可以使用file:file-to-byte-array-transformer。

使用MEL设置parentid以从消息属性中获取值。 因此,如果您有先前的SFDC操作,则可以使用MEL来提取上一个sobject的值。