1

Transform Json format as below

Input:

["100555809","100000001"]

into the following format so that it can be used in the SOQL query by assigning the transformed output some flow variable in salesforce connector.

Output:

('100555809','100000001')
SDE
  • 85
  • 1
  • 13
  • @Moderators, in case this is irrelevant question, please let me know the solution and then I can bring this post down(delete it). – SDE Nov 01 '18 at 17:07
  • Can you elaborate a bit on what you're trying to accomplish? There might be better ways to do this than creating a string that represents a SOQL array. – jerney Nov 01 '18 at 19:50
  • I want to achieve the output via dataweave in Mule. For now I am using a expression component. So just wanted to know if there is any better way to do it. I have edited the post with expression component that I am using. – SDE Nov 01 '18 at 20:09

1 Answers1

1

Assuming your input is the payload and you want a string as output, you'll want to use map to wrap all your IDs in single quotes, then joinBy to join them into a single string. Finally, you'll wrap the result in parenthesis:

%dw 1.0
%output application/java

%var ids = payload

// Wrap ids in single quotes and join them into a string
%function formatIds(ids)
  ids 
    map ((id) -> "'$(id)'")
    joinBy ","

%function transformForSOQL(ids)
  "($(formatIds(ids)))"
---
transformForSOQL(ids)

Not sure if SOQL is exposed to the same vulnerabilities, but if it is, be careful of "SOQL" injection when generating dynamic query values like this.

jerney
  • 2,187
  • 1
  • 19
  • 31