问题描述
我在m子中建立了一个流程,该流程使用"Salesforce"连接器在Salesforce中创建了一个案例.现在,我需要使用相同的m流将文件上传到该情况.可以通过以下代码以编程方式完成此操作:
i builded a flow in mule which create a case in Salesforce using 'Salesforce' connector. now i need to upload a file to that case using the same mule flow. This can be done programatically by the following code:
尝试{
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());
}
但为了简单起见,是否有任何m子连接器会自动完成所有这些操作并将文件附加到特定的已创建案例.
But to make it simple, does there is any mule connector which automatically done all this and attach a file to the particular created case.
推荐答案
是的,您可以为此使用Salesforce Cloud Connector.示例:
Yes you can use the Salesforce Cloud Connector for that. Example:
<file:file-to-byte-array-transformer />
<sfdc:create type="Attachment">
<sfdc:objects>
<sfdc:object>
<body>#[payload]</body>
<name>test.docx</name>
<parentid>#[message.inboundProperties['mysfdcparentid']]</parentid>
</sfdc:object>
</sfdc:objects>
</sfdc:create>
在示例中,我将sobject类型设置为附件".
In the example, I am setting the sobject type to 'Attachment'.
body元素是文件本身.请注意,连接器将为您处理base64编码,您只需要为其提供一个字节数组即可.如果您使用的是File,则可以使用例如file:file-to-byte-array-transformer.
The body element is the file itself. Note that the connector will handle the base64 encoding for you, you just need to provide it with a byte array. If you're using File, you can use file:file-to-byte-array-transformer for example.
使用MEL设置了父代,以从message属性获取值.因此,如果您以前执行过SFDC操作,则可以使用MEL提取以前的sobject的值.
The parentid is set using MEL to get the value from a message property. So if you have a previous SFDC operation you can use MEL to extract the value of the previous sobject.
这篇关于使用连接器将文件上传到Salesforce的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!