Skip to main content

I have situation where a field in Salesforce stores the list of id’s in JSON format. I need a code to set the condition on a model with the values IN (the list of id’s in JSON string). Thanks in advance.

Hey Shiva,

I haven’t tested this code. This is just conceptual. You’ll have to adapt it to an actual snippet.

The general idea is that you can do this by using javascript’s JSON.parse() function to parse the ids into a javascript list, then populate a multiple value condition with the ids in that list.

So something like this.



modelToFilter = skuid.model.getModel('modelToFilter');<br>multipleCond = modelToFilter.getCondition('multipleIdCondition');<br>ids = t]<br>//assuming the field is in the first model. Adjust this to get the correct row<br>row = skuid.model.getModel('ModelWithStoredIds').getFirstRow();<br>//get unparsed ids<br>unparsed = row.fieldWithJson;<br>//here's where you'll need to do a little messing around. Depending on your JSON schema/structure,<br>// there may be a different path to your ids.&nbsp;<br>//for example if your list is named 'ids' in json, you would accedd the ids through be parsed.ids<br>//I'm going to assume it's directly in your JSON as the root item<br>parsed = JSON.parse(unparsed);<br><br>modelToFilter.setCondition(multipleCond,parsed)<br>return modelToFilter.updateData();

Did you find a solution for this? I think it is setting the condition as ‘=’ rather than ‘IN’ and throwing an exception for me.