salesforce connector in Mule - SOQL long query is not working properly for some objects - like product2 - mule

I am facing an issue while running product2 SOQL long query in Mule salesforce Connector. I am able to run and got successful json message with certain fields like Id, Name, ProductCode, Description etc . But some other fields are not working like... Units__c, Stock_Item__c, Sub_Category__c etc. Non working fields are not available as well while I was selecting with "Query builder" in "DataSense Query Language". I guess those fields are customs made from my organization. But All kinds of queries are working perfectly on Salesforce developer console. I am looking for solution so that i can invoke all the fields with result from salesforce product object.
My GET URL :
http://localhost:8081/xxxxxxx/product2?lastModifiedDate=20180629215028
AnyPoint Studio Version: 6.4.2
MuleRuntime 3.9.0
Salesforce Connector - Mule 3 - version : 8.6.0
salesforce API version 40
salesfroce url
:https://xxxxxxxxx.cs96.my.salesforce.com/services/Soap/u/40.0
Tried Also :
with Native Query Language. but unsuccessful.
Thanks in advance !
Mule Configuration XML
<flow name="salesforce_invoking_all_product2_information_flow">
<logger level="INFO" doc:name="Get product2 -Start" message="Get product2- Start"/>
<dw:transform-message doc:name="Transform Message">
<dw:input-payload doc:sample="sample_data\json.json"/>
<dw:input-inbound-property doc:sample="sample_data\Map_1.dwl" propertyName="http.query.params"/>
<dw:set-variable variableName="lastModifiedDateTime"><![CDATA[%dw 1.0
%output application/java
---
(((inboundProperties."http.query.params".lastModifiedDate as :string)
as :localdatetime {format: "yyyyMMddHHmmss"})
as :string {format: "yyyy-MM-dd'T'HH:mm:ss'.000Z'"})
]]></dw:set-variable>
</dw:transform-message>
<sfdc:query-all config-ref="Salesforce_Basic_Authentication" query="dsql:SELECT Id, Name, ProductCode, Description, IsActive, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp, RecordTypeId, Family, ExternalDataSourceId, ExternalId, DisplayUrl, QuantityUnitOfMeasure, IsDeleted, LastViewedDate, LastReferencedDate, Account_Number__c, Color__c, Cost_PO__c, Inventoried_Item__c, Length__c, Paint_Stain_Misc_Job_and_Unit_Charges__c, Style_Code__c, SalesforceID__c, Units__c, Number_Service_Products__c, Master_Legacy_Product__c, Has_Service_Products__c, Products_Joined__c, Number_of_Units__c, Mull_Sequence__c, Mull_Number__c, Mull_Material__c, Mull_Assembly_Type__c, isStandard__c, Unit_of_Measure__c, Stock_Item__c, Sub_Category__c, Cross_Reference__c, Width__c, Category__c, Pivotal_Id__c, Height__c, Unit_Short_Description__c, UI_Minimum__c, UI_Maximum__c, Service_PO__c, Report_Grouping__c, Master_Product__c, Name_Part_Number__c, Part_Number__c, Product_Configuration__c, Product_Image__c, Vendor__c, Product_PO__c, Product_Type__c FROM Product2 limit 10" doc:name="get product 2 details"/>
<json:object-to-json-transformer doc:name="Object to JSON"/>
<logger message="Get Contact- Finish" level="INFO" doc:name="Get Product 2 Finish"/>
</flow>
ERROR Console
Message : org.mule.modules.salesforce.exception.SalesforceException (org.codehaus.jackson.map.JsonMappingException)
Payload : org.mule.streaming.ConsumerIterator#6b1280fb
Transformer : ObjectToJson{this=599abd04, name='ObjectToString', ignoreBadInput=false, returnClass=SimpleDataType{type=java.lang.String, mimeType='application/json', encoding='null'}, sourceTypes=[]}
Payload Type : org.mule.streaming.ConsumerIterator
Element : /salesforce_invoking_all_product2_information_flow/processors/3 # rba-salesforce-product-system:implementation.xml:26 (Object to JSON)
Element XML : <json:object-to-json-transformer doc:name="Object to JSON"></json:object-to-json-transformer>
--------------------------------------------------------------------------------
Root Exception stack trace:
[InvalidFieldFault [ApiQueryFault [ApiFault exceptionCode='INVALID_FIELD'
exceptionMessage='
Style_Code__c,SalesforceID__c,Units__c,Number_Service_Products__c
^
ERROR at Row:1:Column:390
No such column 'Units__c' on entity 'Product2'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.'
extendedErrorDetails='{[0]}'
]
row='1'
column='390'
]
]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at com.sforce.ws.bind.TypeMapper.readSingle(TypeMapper.java:673)
at com.sforce.ws.bind.TypeMapper.readObject(TypeMapper.java:556)
at com.sforce.ws.transport.SoapConnection.parseDetail(SoapConnection.java:236)
at com.sforce.ws.transport.SoapConnection.createException(SoapConnection.java:210)
at com.sforce.ws.transport.SoapConnection.receive(SoapConnection.java:156)
at com.sforce.ws.transport.SoapConnection.send(SoapConnection.java:99)
at com.sforce.soap.partner.PartnerConnection.queryAll(PartnerConnection.java:836)
at org.mule.modules.salesforce.SalesforceConnector$2.doQuery(SalesforceConnector.java:877)

Related

How to concatenate in mule logger?

I need to concatenate text with json payload in logger component. I have tried below ways but no luck
<logger level="INFO" doc:name="Logger" doc:id="38de876a-a64f-4d83-86a1-ef4cbbda167c" message="#['payload is:' + payload]"/>
Even i don't see any transformers like 'object to string converter' in mule 3.
Please suggest syntax for mule 4
Try separating the text from your dataweave
i.e.
<logger level="INFO" doc:name="Logger" mesage="Payload is: #[payload]" doc:id="38de876a-a64f-4d83-86a1-ef4cbbda167c" />
All the various transformers were removed in Mule 4 due to the payload always being "accessible". That is, regardless of the payload type (XML, JSON, Java, CSV...) you can access fields through payload.{fieldname}. In Mule 3.x the payload had to be coerced to a Java object to allow that. You can explicitly set the output type of any dataweave expression, so you can also try:
mesage="Payload is: #[output application/java --- payload]"
It is working with below syntax
<logger level="INFO" doc:name="Logger" doc:id="38de876a-a64f-4d83-86a1-ef4cbbda167c" message="#['payload is:' ++ payload]"/>
I had the same issue and the below worked for me...
<logger level="INFO" doc:name="Logger" doc:id="35d4566e-02ba-495a-bd40-c30aa5a90413" message="#['Get Accounts Response Paylaod : #[payload]']"/>

Mule Server 3.6 > Anypoint Studio > Raw JSON as POST data

Still learning Mulesoft's Anypoint Studio... I am confused as how will I be able to access raw JSON POST data via the HTTP Listener then use the Choice flow control to execute conditions based on a value from a given JSON index. Anyone can show/tell me how to do this?
The JSON HTTP body will automatically become the payload of your message in Mule probably represented as Stream.
Just for demo purposes, try logging the payload after your http:listener using:
<object-to-string-transformer />
<logger level="INFO" message="#[payload]" />
There best way to query JSON is to transform it to a Map suing the JSON module transformers.
<json:json-to-object-transformer returnClass="java.util.HashMap" />
And then query it using MEL like standard MVEL or Java syntax.
For a JSON document like: {"person" : {"name" : "bob"}}
<logger message="#[payload.person.name]" level="INFO" />
You can use these expressions in your choic router also:
<choice>
<when expression="#[payload.person.name == 'bob']">
do something ...
</when>
</choice>

How to get the required data when the payload after the all component is of CopyOnWriteArrayList<Object> type?

Currently I m working on Mule 3.4.2 EE. I have one doubt regarding Mule All coponent. In all block iam calling two flow refs to get the data and after the mule all component is of type CopyOnWriteArrayList<Object> How can i get the data?? Thanks in advance.
<sub-flow name="Aggregating_Flow" doc:name="Aggregating_Flow">
<logger level="INFO" doc:name="Logger"/>
<all doc:name="All">
<flow-ref name="PHYBMDATAReportingDataFetchFlow" doc:name="PHYBMDATAReportingDataFetchFlow"/>
<flow-ref name="PHYBMDATABOALFReportingDataFetchFlow" doc:name="PHYBMDATABOALFReportingDataFetchFlow"/>
</all>
<logger level="INFO" doc:name="Logger" message="paaaaaayload is #[payload:]"/>
<component class="com.xxx.bmrs.api.util.PrepareBMRSPHYBMDATAXMLResponse" doc:name="PrepareBMRSPHYBMDATAXMLResponse"/>
<logger level="INFO" doc:name="Logger"/>
</sub-flow>
after the all coponent i m using java component. How can i get the data i m getting the following exception..
********************************************************************************
Message : Payload was invalidated calling setPayload and the message is not collection anymore. (java.lang.IllegalStateException). Message payload is of type: PHYBMDATARequest
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. Payload was invalidated calling setPayload and the message is not collection anymore. (java.lang.IllegalStateException)
org.mule.DefaultMessageCollection:104 (null)
2. Payload was invalidated calling setPayload and the message is not collection anymore. (java.lang.IllegalStateException). Message payload is of type: PHYBMDATARequest (org.mule.api.MessagingException)
org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor:32 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
java.lang.IllegalStateException: Payload was invalidated calling setPayload and the message is not collection anymore.
at org.mule.DefaultMessageCollection.checkValidPayload(DefaultMessageCollection.java:104)
at org.mule.DefaultMessageCollection.newThreadCopy(DefaultMessageCollection.java:309)
at org.mule.DefaultMuleEvent.newThreadCopy(DefaultMuleEvent.java:799)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
See this bug here: https://www.mulesoft.org/jira/browse/MULE-6795
You can add a combine-collections-transformer after the all router.
Or better yet change your all router to scatter-gather if you can: http://www.mulesoft.org/documentation/display/current/Scatter-Gather

MULE ESB: Saving result from Sql query in Session Variable

I have created a sample mule application that fetches one row from my database.
It fetches USER_NAME and USER_ID from the Database.
when I convert the result to JSON or XML I get the output as
[{"USER_ID":"U001","USER_NAME":"Dharmin"}]
Now i want to save USER_ID and USER_NAME in Session variables.
Can someone guide me ?
edit: updated the basic flow image
After converting to JSON Add this :-
<json:json-to-object-transformer returnClass="java.util.HashMap" doc:name="JSON to Object"/>
and after that put the value into session variable using the following :-
<set-session-variable doc:name="Session Variable" value="message.payload.USER_ID" variableName="USER_ID"/>
and
<set-session-variable doc:name="Session Variable" value="message.payload.USER_NAME" variableName="USER_NAME"/>
Do you need to use the results from the DB as a Json?
If not, don't even bother converting the values to JSON before saving them to the sessionVars. Access them directly from the Payload after the DB call:
And here's the configuration XML:
<flow name="testsFlow">
<db:select config-ref="ORacle_DBCP_Config" doc:name="inputdata">
<db:parameterized-query><![CDATA[SELECT 'U001' AS USER_ID, 'Dharmin' AS USER_NAME FROM DUAL]]></db:parameterized-query>
</db:select>
<set-session-variable variableName="userName" value="#[payload[0].USER_NAME]" doc:name="userName"/>
<set-session-variable variableName="userID" value="#[payload[0].USER_ID]" doc:name="userID"/>
<logger message="#["UserID: " + sessionVars.userID + " | UserName: " + sessionVars.userName]" level="INFO" doc:name="Output the test"/>
</flow>
The output of the logger is:
processor.LoggerMessageProcessor: UserID: U001 | UserName: Dharmin

How to read SQL queries from properties file in Mule 3.5 Database connector

I have a Mule flow which is fetching Data from Database using Mule 3.5 Database connector ... My Mule Flow is following :-
<flow name="BestelItems" doc:name="BestelItems">
<poll doc:name="Poll">
<fixed-frequency-scheduler frequency="30" timeUnit="SECONDS"/>
<db:select config-ref="Generic_Database_Configuration" doc:name="Database">
<db:parameterized-query><![CDATA[select * from getData]]></db:parameterized-query>
</db:select>
</poll>
<mulexml:object-to-xml-transformer doc:name="Object to XML"/>
<logger message="Payload :- #[message.payload]" level="INFO" doc:name="Logger" />
</flow>
Now this works fine and fetch all the Data from DB and display in console using logger ..
Now the issue is, if I try to read the query from a property file then it throws an exception ... for example if I put the SQL query select * from getData in a Property file like the following :- QueryFromPropertyfile= select * from getData and then try to read the value in the flow like :-
<db:select config-ref="Generic_Database_Configuration" doc:name="Database">
<db:parameterized-query><![CDATA[${QueryFromPropertyfile}]]></db:parameterized-query>
</db:select>
Then it generate the following exception :-
ERROR 2014-08-02 22:39:51,064 [pool-14-thread-1] org.mule.exception.DefaultSystemExceptionStrategy: Caught exception in Exception Strategy: Query type must me '[SELECT, STORE_PROCEDURE_CALL]' but was 'DDL'
java.lang.IllegalArgumentException: Query type must me '[SELECT, STORE_PROCEDURE_CALL]' but was 'DDL'
at org.mule.module.db.internal.processor.AbstractDbMessageProcessor.validateQueryType(AbstractDbMessageProcessor.java:164)
at org.mule.module.db.internal.processor.AbstractSingleQueryDbMessageProcessor.executeQuery(AbstractSingleQueryDbMessageProcessor.java:40)
at org.mule.module.db.internal.processor.AbstractDbMessageProcessor.process(AbstractDbMessageProcessor.java:66)
at org.mule.transport.polling.MessageProcessorPollingMessageReceiver$1.process(MessageProcessorPollingMessageReceiver.java:164)
at org.mule.transport.polling.MessageProcessorPollingMessageReceiver$1.process(MessageProcessorPollingMessageReceiver.java:148)
at org.mule.execution.ExecuteCallbackInterceptor.execute(ExecuteCallbackInterceptor.java:16)
at org.mule.execution.HandleExceptionInterceptor.execute(HandleExceptionInterceptor.java:30)
at org.mule.execution.HandleExceptionInterceptor.execute(HandleExceptionInterceptor.java:14)
at org.mule.execution.BeginAndResolveTransactionInterceptor.execute(BeginAndResolveTransactionInterceptor.java:54)
at org.mule.execution.ResolvePreviousTransactionInterceptor.execute(ResolvePreviousTransactionInterceptor.java:44)
at org.mule.execution.SuspendXaTransactionInterceptor.execute(SuspendXaTransactionInterceptor.java:50)
at org.mule.execution.ValidateTransactionalStateInterceptor.execute(ValidateTransactionalStateInterceptor.java:40)
at org.mule.execution.IsolateCurrentTransactionInterceptor.execute(IsolateCurrentTransactionInterceptor.java:41)
at org.mule.execution.ExternalTransactionInterceptor.execute(ExternalTransactionInterceptor.java:48)
at org.mule.execution.RethrowExceptionInterceptor.execute(RethrowExceptionInterceptor.java:28)
at org.mule.execution.RethrowExceptionInterceptor.execute(RethrowExceptionInterceptor.java:13)
at org.mule.execution.TransactionalErrorHandlingExecutionTemplate.execute(TransactionalErrorHandlingExecutionTemplate.java:109)
at org.mule.execution.TransactionalErrorHandlingExecutionTemplate.execute(TransactionalErrorHandlingExecutionTemplate.java:30)
at org.mule.transport.polling.MessageProcessorPollingMessageReceiver.pollWith(MessageProcessorPollingMessageReceiver.java:147)
at org.mule.transport.polling.MessageProcessorPollingMessageReceiver.poll(MessageProcessorPollingMessageReceiver.java:138)
at org.mule.transport.AbstractPollingMessageReceiver.performPoll(AbstractPollingMessageReceiver.java:216)
at org.mule.transport.PollingReceiverWorker.poll(PollingReceiverWorker.java:80)
at org.mule.transport.PollingReceiverWorker.run(PollingReceiverWorker.java:49)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:351)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
ERROR 2014-08-02 22:40:20,667 [pool-14-thread-1] org.mule.exception.DefaultSystemExceptionStrategy: Caught exception in Exception Strategy: Query type must me '[SELECT, STORE_PROCEDURE_CALL]' but was 'DDL'
java.lang.IllegalArgumentException: Query type must me '[SELECT, STORE_PROCEDURE_CALL]' but was 'DDL'
at org.mule.module.db.internal.processor.AbstractDbMessageProcessor.validateQueryType(AbstractDbMessageProcessor.java:164)
at org.mule.module.db.internal.processor.AbstractSingleQueryDbMessageProcessor.executeQuery(AbstractSingleQueryDbMessageProcessor.java:40)
at org.mule.module.db.internal.processor.AbstractDbMessageProcessor.process(AbstractDbMessageProcessor.java:66)
at org.mule.transport.polling.MessageProcessorPollingMessageReceiver$1.process(MessageProcessorPollingMessageReceiver.java:164)
at org.mule.transport.polling.MessageProcessorPollingMessageReceiver$1.process(MessageProcessorPollingMessageReceiver.java:148)
at org.mule.execution.ExecuteCallbackInterceptor.execute(ExecuteCallbackInterceptor.java:16)
at org.mule.execution.HandleExceptionInterceptor.execute(HandleExceptionInterceptor.java:30)
at org.mule.execution.HandleExceptionInterceptor.execute(HandleExceptionInterceptor.java:14)
at org.mule.execution.BeginAndResolveTransactionInterceptor.execute(BeginAndResolveTransactionInterceptor.java:54)
at org.mule.execution.ResolvePreviousTransactionInterceptor.execute(ResolvePreviousTransactionInterceptor.java:44)
Please help .. what should I need to do to read SQL queries from properties file in the new Mule 3.5 Database connector .. I have searched all through the net .. but couldn't able to find solution ...
It seems like for any reason, properties can be used in DB queries (feels like a bug IMO, I suggest you report it to MuleSoft).
So another option would be to create a flow variable with the query in it and use it:
<flow name="the_flow">
<poll>
<fixed-frequency-scheduler frequency="30" timeUnit="SECONDS"/>
<processor-chain>
<set-variable variableName="selectQuery" value="${QueryFromPropertyfile}" />
<db:select config-ref="Generic_Database_Configuration">
<db:dynamic-query>#[flowVars.selectQuery]</db:dynamic-query>
</db:select>
</processor-chain>
</poll>
..
</flow>
I had the same issue. As #David suggested I added a flow var and inserted the query (from a property).The only difference was I had to add the CDATA section below. I was able to pull the query from a property file after that. Here is my flow:
<sub-flow name="OpenSubFlow" doc:name="OpenSubFlow">
<set-variable variableName="openQuery" value="${opens}" doc:name="Open Var"/>
<db:select config-ref="MySQL_Configuration" doc:name="Opens">
<db:dynamic-query><![CDATA[#[flowVars.openQuery]]]></db:dynamic-query>
</db:select>
</sub-flow>