How to create comma...
 
Notifications
Clear all

[Solved] How to create comma separated values to use in the IN clause in SOQL

2 Posts
1 Users
0 Likes
524 Views
Posts: 192
 CWL
Admin
Issue starter
(@cwl)
Member
Joined: 11 years ago

Create string values to be used in the IN Clause of a WHERE condition in SOQL

Issue Tags
1 Reply
Posts: 192
 CWL
Admin
Issue starter
(@cwl)
Member
Joined: 11 years ago
            jsonBody = '[{"count__c":"445", "downloads__c":"340"}, {"count__c":"440", "downloads__c":"240"}]';

	    List dList = (List) System.JSON.deserialize(jsonBody, List.class);

	    countList has unique count__c values, say: 445,440 // to use in the IN clause.

	    // Create a string of unique plan ids to use in the IN clause
            set<String> sSet = new set<String>();
            String strCounts = '';

            for(Data__c d : dList) {
                sSet.add(d.count__c__c);
            }
            for(String ss : sSet) {
                strCounts += ss+',';
            }
            strCounts = strCounts.removeEnd(',');
            list<String> countList = strCounts.split(','); // to use in the IN clause

            // Querry parent for those plan ids in daily data json
            List<Parent__c> cList = [SELECT Id, Name, Count__c FROM Parent__c 
                WHERE count__c IN countList];
Reply
Share: