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')
3
  • @Moderators, in case this is irrelevant question, please let me know the solution and then I can bring this post down(delete it). Commented Nov 1, 2018 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. Commented Nov 1, 2018 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. Commented Nov 1, 2018 at 20:09

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your help @jerney
No problem. If this answer worked for you please accept it! stackoverflow.com/help/someone-answers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.