0
votes

I'm developing an integration using Mule ESB which needs to read a binary file (.zip) from the file system and create it as an attachment in Salesforce. However, I'm not able to get this work and I'm getting the following error:

INFO  2016-03-11 13:55:47,338 [[sfdc].File.receiver.01]       org.mule.transport.file.FileMessageReceiver: Lock obtained on file: /Users/aaa/Desktop/temp/files/test.zip
INFO  2016-03-11 13:55:47,345 [[sfdc].sfdcFlow.stage1.02] org.mule.api.processor.LoggerMessageProcessor: Payload = org.mule.transport.file.ReceiverFileInputStream@4f0870aa
INFO  2016-03-11 13:55:47,348 [[sfdc].sfdcFlow.stage1.02] com.mulesoft.weave.mule.utils.MuleWeaveFactory$: MimeType was not resolved 'application/zip' delegating to Java.
ERROR 2016-03-11 13:55:47,367 [[sfdc].sfdcFlow.stage1.02] org.mule.exception.DefaultMessagingExceptionStrategy: 
Message               : Could not find a transformer to transform "SimpleDataType{type=java.util.LinkedHashMap, mimeType='*/*', encoding='null'}" to "CollectionDataType{type=java.util.List, itemType=java.lang.Object, mimeType='*/*'}".
Type                  : org.mule.api.transformer.TransformerException
Code                  : MULE_ERROR-236
JavaDoc               : http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transformer/TransformerException.html
Exception stack is:
1. Could not find a transformer to transform "SimpleDataType{type=java.util.LinkedHashMap, mimeType='*/*', encoding='null'}" to "CollectionDataType{type=java.util.List, itemType=java.lang.Object, mimeType='*/*'}". (org.mule.api.transformer.TransformerException)
 org.mule.registry.MuleRegistryHelper:248 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transformer/TransformerException.html)
Root Exception stack trace:
org.mule.api.transformer.TransformerException: Could not find a transformer to transform "SimpleDataType{type=java.util.LinkedHashMap, mimeType='*/*', encoding='null'}" to "CollectionDataType{type=java.util.List, itemType=java.lang.Object, mimeType='*/*'}".

Here is the configuration file.

<sfdc:config name="Salesforce__Basic_Authentication" username="[email protected]" password="password" securityToken="token" url="https://test.salesforce.com/services/Soap/u/34.0" doc:name="Salesforce: Basic Authentication"/>
<file:connector name="File" readFromDirectory="/Users/aaa/Desktop/temp/files" autoDelete="true" streaming="true" validateConnections="true" doc:name="File"/>
<flow name="sfdcFlow">
    <file:inbound-endpoint path="/Users/aaa/Desktop/temp/files" connector-ref="File" responseTimeout="10000" doc:name="File"/>
    <logger message="Payload = #[payload]" level="INFO" doc:name="Logger"/>
    <object-to-byte-array-transformer doc:name="Object to Byte Array"/>
    <dw:transform-message doc:name="Transform Message">
        <dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
{
ParentId: "b2U7A0B01054OyZ",
Name: "Test Name",
Description: "Test Descr",
Body: payload
}]]></dw:set-payload>
    </dw:transform-message>

    <sfdc:create config-ref="Salesforce__Basic_Authentication" type="Attachment" doc:name="Salesforce" />
</flow>

I checked the Anypoint exchange and googled, but all the pointers that I'm getting is geared towards text files (like CSVs). Appreciate if someone can share a working example to read a binary file and create it as an attachment in Salesforce (can attach to any object like case object).

I'm using Anypoint Studio 5.4.1 with Mule runtime 3.7.3 EE.

Edit: I was able to resolve the issue. Basically, as @david said, the create method takes a collection and I was not passing it as a collection. Here is the updated code (just the dataweave part):

[
  {
    ParentId: "b2U7AB010540yZ",
    Name: "Test Name",
    Description: "Test Descr",
    Body: payload
  }
]

Note the open and close square brackets. Thanks @david.

1

1 Answers

1
votes

What I understand from the SFDC Connector doc, is that the create method expects a collection of objects.

But you're passing a map to it, thus this exception:

Could not find a transformer to transform "SimpleDataType{type=java.util.LinkedHashMap, mimeType='*/*', encoding='null'}" to "CollectionDataType{type=java.util.List, itemType=java.lang.Object, mimeType='*/*'}"

Try adding the map you create in dw:transform-message to a list, using a transformer for this, and it should work.