To create multiple records in salesforce using mule salescloud connector - mule

I am trying to upload many records to salesforce via mule using (create bulk) operation.
I created the flow as below
<flow name="bulk_salesFlow1" doc:name="bulk_salesFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/>
<sfdc:create-bulk config-ref="Salesforce12" type="BulkMule__c" doc:name="Salesforce">
<sfdc:objects>
<sfdc:object>
<sfdc:inner-object key="Component__c">Transformer</sfdc:inner-object>
<sfdc:inner-object key="Use__c">Transforms the payload</sfdc:inner-object>
</sfdc:object>
<sfdc:object>
<sfdc:inner-object key="Use__c">Iterator</sfdc:inner-object>
<sfdc:inner-object key="Component__c">ForEach</sfdc:inner-object>
</sfdc:object>
</sfdc:objects>
</sfdc:create-bulk>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
</flow>
I am getting error "Element: Object is not allowed to be repeated". I would like to know if I'm trying in the right way, if so what is wrong in the above flow.
Thank you in advance

I think this is just a problem with Mule Studio, and you should be able to run your flow if you just ignore the warnings.
If the warnings bother you, you can always use <sfdc:objects ref="#[something]"/> with a list of maps with field names corresponding to your SF object.

Related

Mule-Unable to access Session Variable value in another flow

I need to retrieve the value set in session variable in flow1 to flow2. The code I've written looks like this :
<flow name="demo1Flow">
<http:listener config-ref="HTTP_Listener_Configuration" path="demo" doc:name="HTTP"/>
<set-session-variable variableName="name" value="balwant" doc:name="Session Variable"/>
<logger message="Inside demo1 #[sessionVars.name]" level="INFO" doc:name="Logger"/>
<http:request config-ref="HTTP_Request_Configuration" path="/test" method="GET" doc:name="HTTP"/>
</flow>
<flow name="demoFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/test" doc:name="HTTP"/>
<logger message="Inside demo flow #[sessionVars['name']]" level="INFO" doc:name="Logger"/>
</flow>
With the above code I'm not able to get the value from session variable which was set in demo1Flow to demoFlow. The output for this flow I'm getting is :
INFO 2017-03-07 12:55:28,455 [[demo].HTTP_Listener_Configuration.worker.01] org.mule.api.processor.LoggerMessageProcessor: Inside demo1 balwant
INFO 2017-03-07 12:55:28,536 [[demo].HTTP_Listener_Configuration.worker.02] org.mule.api.processor.LoggerMessageProcessor: Inside demo flow null.
As the documentation says that value in Session variable is accessible across the session in different flows, but here that is not happening :(. Not sure what is the reason.
Referring Session Variable Transformer Reference documentation, the Session Variable persist for the entire message lifecycle, regardless of transport barriers, except for the HTTP Connector which doesn’t propagate them.
They are two independent flows which process messages based on different input paths, although you are calling using http requester from flow1,second has its own scope.
For every flow it's scope begins with its inbound.
As there is no relationship between those two flows, you can't access anything from flow1 in the other. If you want that variable you can set as outbound property then it will become inbound property to the second flow. Otherwise you can set as uri parameters.
Regards,
Mallesh

How to send array in url in mule esb?

I need to send array in url. I have tried different ways like
http://localhost:8081/?RedundedItems[]=[00,11]
http://localhost:8081/?RedundedItems[]=00,11
http://localhost:8081/?RedundedItems=00&RedundedItems=11
http://localhost:8081/?RedundedItems[]=00&RedundedItems[]=11
Please assist me.
Sorry but I really dont think this is possible or even if by some miracle it is, I dont see it as practical...
One solution would be to send your data as normal and maybe process it into an array via datamapper?
Hope I have been of some help.
JB
The following works using your third option:
<flow name="request-testFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
<set-payload value="#[message.inboundProperties.'http.query.params'.getAll('RedundedItems')]" doc:name="Set Payload"/>
<object-to-string-transformer doc:name="Object to String"/>
</flow>
So hitting http://localhost:8081/?RedundedItems=00&RedundedItems=11 the output is: [00, 11].
HTH.
The right way is http://localhost:8081/?RedundedItems=00,11 . You can't specify the parameter is an array.

How to Extract the Flow Name and MessageProcessor Name using MEL - MULE ESB

I'm not sure, how can we extract the flow-name and message-processor Name through MEL. For example I have multiple message processor. For logging, i need to extract the flow Name and Message-processor, so that I can find out transaction has crossed this particular flow and its message processor. Is there any simple way to find out. Please guide me. Please find the screenshot below. Here i need to Extract - set payload and its flowName (flow1)
Thanks in advance.
For mule 3.8+ version onwards #[flow.name] don't work.
Use #[mule:context.serviceName] expression in logger or component to extract the name of the flow
I know this post is old but I have been trying to find a way to do this in MEL for error handling emails.
For the flow name you can use #[exception.event.flowConstruct.name]
for the failing message processor you can use #[exception.failingMessageProcessor].
Both of these work in MEL without the need to use an flowVar.
Please note however, that the failing processor does not always come back with a value but comes back with null, I'm not sure why.
You can extract the flow-name with MEL : #[flow.name]
<flow name="name" doc:name="name">
<http:inbound-endpoint address="http://localhost:8090/resources" doc:name="HTTP" />
<logger message="name of flow: #[flow.name]" level="INFO" doc:name="Logger"/>
<set-payload value="name" doc:name="Set Payload"/>
</flow>
or
flowConstruct.getName() in a Message Processor
Two ways to acthive this (from current flow name)
First one is -
<logger message="Current flowName: #[flow.name]" level="INFO" doc:name="Logger"/>
and the second one is -
<logger message="Current flowName: #[context:serviceName]" level="INFO" doc:name="Logger"/>

How's Mule <object-to-string-transformer> different than message.getPatyloadAsString()

I've a soap service flow which gets inbound request through <cxf:proxy-service>. I have a set payload right after it to get payload as String.
Here is my flow:
<flow name="soapService">
<http:inbound-endpoint address="${service.address}" exchange-pattern="request-response">
<cxf:proxy-service wsdlLocation="classpath:service.wsdl" namespace="http://pennmutual.com/services/mvi" service="MVIService" enableMuleSoapHeaders="false"/>
</http:inbound-endpoint>
<set-payload value="#[message.payloadAs(java.lang.String)]"/>
.
.
.
</flow>
<set-payload value="#[message.payloadAs(java.lang.String)]"/> works but if I replace it with <object-to-string-transformer>, it doesn't work.
How are these 2 inherently different?
UPDATE:
On replacing <set-payload value="#[message.payloadAs(java.lang.String)]"/> with <object-to-string-transformer> in my above flow, #[payload] gives com.ctc.wstx.sr.ValidatingStreamReader#429eb61a instead of the atcual XML
message.payloadAs(java.lang.String) relies on Mule's auto-transformation framework: I supposed it picks <xml:dom-to-xml-transformer> instead of <object-to-string-transformer> as the most appropriate transformer.

Mule JDBC Rest servce

I have requirement for to fetch data from Database and expose the content as Restful service, I am unable to find any useful documents.
Can any one please share the documents or links.
Take a look at http://www.mulesoft.org/extensions/rest-module
You can combine it with JDBC endpoints to fetch data from the DB.
A simple example will be :-
<flow name="testFlow">
<http:listener config-ref="HTTP_InboundRequest" path="/test" doc:name="HTTP"/>
<set-variable doc:name="Variable" value="23" variableName="eventId"/>
<db:select config-ref="Oracle_Configuration" doc:name="Database">
<db:parameterized-query><![CDATA[select ID, NAME where EVENT_ID=#[flowVars['eventId']]]]></db:parameterized-query>
</db:select>
<set-payload value="{"status":"Success"}" doc:name="Set Payload"/>
</flow>
Where you can modify the code as per your requirement and display the Database values as JSON response.
So, if you deploy a service similar to this , it will be exposed as a Rest api