function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

URGENT: SOQL query not working with multi picklists field

Need Help: Child Object :-   Test_site_audience__c
                      Master Object :-  Site_Placement__c
Demo__c is multi picklist field on child object. Demo__c has three values 'all', 'Male 12-23','Female 12-23'. There is one more field on chiled object called Impression_share__c. Based on each Demo__c value , Impression_Share__c has some value. i have created a visual force page. I am trying to sum the IMPRESSION_SHARE__C based on whatever user selects in Multi select picklist field. Below is the SOQL query. It is working if user selects one value in multipicklist field. But it is not working if user selects more than one value . Below is SOQL query.

Sumofimpressionshare = (Decimal)([ SELECT sum(Impression__share__c) FROM
             Test_site_audience__c Where (demo__c includes (:test.demo__c)) AND  site_placement_lookup__c in (select id FROM Site_Placements__c WHERE((Ad_Positioning__c like :matchString3)AND (Inventory_Type__c like :matchString4)AND (Language__c like :matchString5)AND (Flagged__c like :matchString6) ) )][0].get('expr0'));
Mariappan PerumalMariappan Perumal

Try to use  = instead of includes .

I tried the same in developer console it works fine.  It may help you .


It is still not working if I select more than one value.
Mariappan PerumalMariappan Perumal
 what is test.demo__c ? is it the values in the multi select picklist ?
Kindly store that in the string variable ? and use that in the query .
Below is my code. I have used in string query But i dont know how to use in string query. "test' is a constructor of Test_Site_Audience__c object. And, Demo__c is multiselect picklist in the same object

public class Fetchsiteplacement1{
public Test_site_audience__c test{get;set;}
    String matchString;
    String matchString1;
    String matchString2;
    String matchString3;
    String matchString4;
    String matchString5;
    String matchString6;
    String matchstring7;
    String values='';
    List<String> myValues=new List<String>{'All','Male 12-23','Female 12-23'};
    public Integer inputText1{get;set;}
    public Integer Mincvr{get;set;}
    public Integer Maxbid{get;set;}
    public Integer daysinflight{get;set;}
    public Integer MininTarget{get;set;}
     //Declare variable to be accessible in vf page
    public decimal Sumofimpressionshare{get;set;}
    public Fetchsiteplacement1(){
        sp=new Site_Placements__c ();
        test = new Test_site_audience__c();
        spRec = new List<Site_Placements__c>();
        matchString = '';
        matchString1 ='';
        matchString2 ='';
        matchString3 ='';
        matchString4 ='';
        matchString5 ='';
        matchString6 ='';
        matchString7 ='';
    public void FillAggregates()
            Sumofimpressionshare = (Decimal)([ SELECT sum(test_audience_number__c) FROM
             Test_site_audience__c Where (demo__c = :test.demo__c) AND  site_placement__c in (select id FROM Site_Placements__c WHERE((eCPM__c <=:Maxbid)AND(CVR__c >=:Mincvr)AND(CTR__c >=:inputtext1)AND(Device_Type__c like :matchString) AND (Auto_Play__c like :matchString1) AND (Number_of_Strikes_Given__c like :matchString2)AND (Ad_Positioning__c like :matchString3)AND (Inventory_Type__c like :matchString4)AND (Language__c like :matchString5)AND (Flagged__c like :matchString6) ) ) ][0].get('expr0'));
             system.debug('sum of impressionshare:'+ Sumofimpressionshare );
  public pagereference CancelSPRec(){
    PageReference page = new PageReference('');
    return page;
Mariappan PerumalMariappan Perumal
Hi .

Can you try to print the test.demo__c in system.debug statement before the query statment. 

If 2 values are choosen in the multi- select picklist means it should be separated by ; between them .(for example:Male 12-23;Female 12-23 ) .

Try to Put system.debug statement in the FillAggregates method and see what is being returned in that string. 

If those values are not separated with ; it would work as we except. 

Kindly try this and let me know if doesnt work this way too.