0
votes

I am trying to use a query with flowvariable in the where clause in Mule ESB (Connecting with Salesforce)

SELECT id FROM Account WHERE CX_ID__c = '"flowvars.orgpayload.CXM_ID+"' LIMIT 1

But I am not getting an error here. Any pointers on how to use flow variable in a query would help. Thanks!

2
Where does this query fit? Can you show the full XML element where you use it? It's hard to provide a complete answer without more context. - David Dossot

2 Answers

1
votes

Flow variables are accessible via MEL, either with flowVars.VAR_NAME, flowVars['VAR_NAME'] (if the variable contains characters that conflicts with MEL's syntax) or directly VAR_NAME (if you have not disabled the default binding of flow variables as top level MEL variables).

In your case, since the flow variable is named orgpayload.CXM_ID, the . makes it conflict with MVEL syntax. So you can not use flowVars.orgpayload.CXM_ID but instead you must use flowVars['orgpayload.CXM_ID']

PS. MEL is case sensitive. You typed flowvars when you wanted flowVars

1
votes

In your case I would have something like the blow

SELECT id FROM Account WHERE CX_ID__c = '#[flowVars['orgpayload.CXM_ID']]' LIMIT 1

In addition to the above, you should consider using Parameterized queries instead of dynamic queries as dynamic queries are prone to SQL injection attacks and are less performant when compared to Parameterized queries.

Refer to this document