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
Paul BrainardPaul Brainard 

How to pass values from a multi-select to further filter my results

Hello Good People,

I want to be able to filter on a notes field on an object.  Currently, the code below is passing a date range from a VF page into an Extension and it's filtering the notes by the date range.  I want to be able to filter further by adding a multi-value picklist on a field called Activities Offered, so the PDF prints just the notes between the date range and for the Activities Offered on the Participant Activity.  I've tried adding the variable stractoff references in the below code, but the result is now showing no notes at all.  Can anyone see what I'm doing wrong and lend a helping hand?
 
public with sharing class CaseNotesController {
// The controller has three modes that it can be invoked
// 1. to specify the date range of case notes to print out for a case (PrintCaseNotes.page)
// 2. to load a single case note to print out for a participant activity (CaseNotesViewPDF)
// 3. to a range of case notes to print out for a case (CaseNotesViewPDF after PrintCaseNotes)

 List<Participant_Activity__c> palist = new List<Participant_Activity__c>();
  
 public Datetime starttime { get ; set; }
 public Datetime endtime { get ; set; }
  
 public String strstarttime { get ; set; }
 public String strendtime { get ; set; }
 
public String stractoff { get ; set; }

 public String getstartdate () {
     if (starttime != null) {
        Date d = date.newinstance(starttime.year(), starttime.month(), starttime.day());
        return d.format();
     } else {
        return null;
     }
 }
  public String getenddate () {
      if (endtime != null) {
        Date d = date.newinstance(endtime.year(), endtime.month(), endtime.day());
        return d.format();
      } else {
        return null;
     }
 }
 
public Participant_Activity__c singlepa {get; set;}
 
 public Program__c program {get;set;}
 public Participant_Case__c c {get;set;}
 
 String cid; // case id that may be passed in via the URL
 String paid; // participant activity id that may be passed in
 
 // wrapper class to contain participant activities and related hours
 public class parActivity {
        public Participant_Activity__c pa {get; set;}
        public List<Participant_Hours__c> phs {get; set;}
        public List<Staff_Hours__c> shs {get; set;}       
        public String padate {get;set;}
        public Integer num {get;set;}
        public Integer shssize {get;set;}
        public Integer phssize {get;set;}
 }
 
 public CaseNotesController(ApexPages.StandardController sc) { 

        c = (Participant_Case__c) sc.getRecord();
        if (c==null || c.id == null) 
                cid = ApexPages.currentPage().getParameters().get('id');        // we should always have a cid
            else
                cid = c.id;

        // get command line params
        strstarttime = ApexPages.currentPage().getParameters().get('starttime');
            strendtime = ApexPages.currentPage().getParameters().get('endtime'); 
             stractoff = ApexPages.currentPage().getParameters().get('stractoff');        
            paid = ApexPages.currentPage().getParameters().get('paid'); // we will only have a paid when invoked from the Participant Activity page
            
            // if a case id is passed in but no paid or starttime, just load the latest PA if there is one
            system.debug('TESTING>>> cid: ' + cid + ', paid: '+paid+', strstarttime: ' + strstarttime);
            if (cid != null && (paid == null || paid.length() < 15) && strstarttime == null) {
                system.debug('DEBUG>>> Only CID passed in. Loading latest PA.');
                try {
                                paid = [select id from Participant_Activity__c where Case__c =:cid order by Start_Time__c desc limit 1].id;             
                } catch (QueryException e) {
                        system.debug(e.getMessage());
                }
            }
            
            // check for next invocation case: invoked from case record            
            if (cid == null && (paid == null || paid.length() < 15)) {
                system.debug('DEBUG>>> Case Notes Controller: No Ids passed in.');
            } else {
        
                CaseManagement cm = new CaseManagement(c);
                program = cm.program;  
                        
                if ((paid == null || paid.length() < 15) && (strstarttime!=null && strendtime!=null)) { // invoked from the Case page
                
                if (strstarttime != null) 
                    starttime = datetime.valueof(strstarttime);
                
                if (strendtime != null) 
                    endtime = datetime.valueof(strendtime);

                singlepa = new Participant_Activity__c (  // in this case this is only used to hold the date range
                    Start_Time__c = starttime,
                    End_Time__c = endtime,
                    Activities_Offered__c = stractoff
                );
                
        } else {  // invoked from the Participant Activity page -- printing single case note
                try {
                    singlepa = [select id, Case_Notes__c, Start_Time__c, Contact_Method_Location__c, Duration_hours__c, End_Time__c, Clinical_Status_WNL_Appearance__c, 
                                    Clinical_Status_Poor_Hygiene__c, Clinical_Status_Poor_Grooming__c, Clinical_Status_WNL_Mood__c, Clinical_Status_Depressed__c, 
                                    Clinical_Status_Angry__c, Clinical_Status_Excitable__c, Clinical_Status_Anxious__c, Clinical_Status_WNL_Affect__c,
                                    Clinical_Status_Flat__c, Clinical_Status_Bright__c, Clinical_Status_Sad__c, Clinical_Status_Expressive__c, Clinical_Status_Good__c,
                                    Clinical_Status_Poor__c, Clinical_Status_Minimal__c, Clinical_Status_Fixed_Gaze__c, Clinical_Status_WNL_Activity_Level__c,
                                    Clinical_Status_Hyperactive__c, Clinical_Status_Agitated__c, Clinical_Status_Slowed__c, Clinical_Status_Medication__c,
                                    Clinical_Status_UAs__c, Clinical_Status_Other_Observations__c, Service_Type__c, Case__c, Activities_Offered__c,
                                    (select id, Staff__c, Duration__c, Service_Code__c, Bill_Code__c from Staff_Hours__r),
                                    (select id, Participant__c, Participant__r.DEM_Family_Role__c, Main_Participant__c, Duration__c, Service_Code__c, Bill_Code__c, Type__c 
                                            from Participant_Hours__r)
                                            //where Participant__c =:c.Participant__c)
                                    from Participant_Activity__c 
                                            where id=:paid limit 1];
                } catch (QueryException e) {
                    system.debug('DEBUG>> No Participant Activities found.');
                } catch (NullPointerException e) {
                    system.debug('DEBUG>> Null Pointer Exception querying for Participant Activities.');
                }
                
                if (singlepa != null) {
                    starttime = singlepa.Start_Time__c;
                    endtime = singlepa.End_Time__c;
                }
                
        }
    }
 } 

 public List<parActivity> activities;
   
 public List<parActivity> getactivities() {
            
     activities = new List<parActivity>(); 
     system.debug('TESTING>>> getactivities: paid ' + paid + ', singlepa: ' + singlepa);
        
     if ((paid != null && paid.length() < 15) && singlepa != null && singlepa.Start_Time__c != null) {  // populate one pa
        parActivity pact = new parActivity();
        pact.pa = singlepa;
        pact.num = 1;
        pact.padate = pact.pa.Start_Time__c.format('M/d/yyyy','PST');
        pact.shs = singlepa.Staff_Hours__r;
        pact.shssize = singlepa.Staff_Hours__r.size();
        pact.phs = singlepa.Participant_Hours__r;
        pact.phssize = singlepa.Participant_Hours__r.size();
        activities.add(pact);
     } else { // load multiple from date range
        // get the participant activities
        Integer o = 0;
        for (Participant_Activity__c pa : [select id, Case_Notes__c, Start_Time__c, Contact_Method_Location__c, Duration_hours__c, End_Time__c, Clinical_Status_WNL_Appearance__c, 
                                Clinical_Status_Poor_Hygiene__c, Clinical_Status_Poor_Grooming__c, Clinical_Status_WNL_Mood__c, Clinical_Status_Depressed__c, 
                                Clinical_Status_Angry__c, Clinical_Status_Excitable__c, Clinical_Status_Anxious__c, Clinical_Status_WNL_Affect__c,
                                Clinical_Status_Flat__c, Clinical_Status_Bright__c, Clinical_Status_Sad__c, Clinical_Status_Expressive__c, Clinical_Status_Good__c,
                                Clinical_Status_Poor__c, Clinical_Status_Minimal__c, Clinical_Status_Fixed_Gaze__c, Clinical_Status_WNL_Activity_Level__c,
                                Clinical_Status_Hyperactive__c, Clinical_Status_Agitated__c, Clinical_Status_Slowed__c, Clinical_Status_Medication__c,
                                Clinical_Status_UAs__c, Clinical_Status_Other_Observations__c, Service_Type__c, Case__c,
                                (select id, Staff__c, Duration__c, Service_Code__c, Bill_Code__c from Staff_Hours__r),
                                (select id, Participant__c, Participant__r.DEM_Family_Role__c, Main_Participant__c, Duration__c, Service_Code__c, Bill_Code__c, Type__c 
                                        from Participant_Hours__r) 
                                        //where Participant__c =:c.Participant__c)
                          from Participant_Activity__c 
                          where Case__r.id =:cid 
                          and Start_Time__c>=:starttime 
                          and Start_Time__c<=:endtime
                          order by Start_Time__c]) {
 
                        parActivity pact = new parActivity();
                        pact.padate = pa.Start_Time__c.format('M/d/yyyy','PST');
                        pact.pa = pa;
                        pact.num = o++;
                        pact.shs = pa.Staff_Hours__r;
                        if (pa.Staff_Hours__r != null)
                                pact.shssize = pa.Staff_Hours__r.size();
                        else
                                pact.shssize = 0;
                        pact.phs = pa.Participant_Hours__r;
                        if (pa.Participant_Hours__r != null)
                                pact.phssize = pa.Participant_Hours__r.size();
                        else
                                pact.phssize = 0;
                        activities.add(pact);           
                                        
        }
        // also load the participant hours from the group activities and translate them into participant activities
        for (Participant_Hours__c ph : [select id, Participant__c, Participant__r.DEM_Family_Role__c, Main_Participant__c, Duration__c, Service_Code__c, Bill_Code__c, 
                                                                                Case_Notes__c, Type__c, Start_Time__c, End_Time__c  
                                                                        from Participant_Hours__c
                                                                        where Case__c =: cid 
                                                                        and Group_Meeting__c != null
                                                                        and Start_Time__c>=:starttime 
                                                                        and Start_Time__c<=:endtime
                                                                        and Activities_Offered__c=: stractoff 
                                                                        order by Start_Time__c ]) {
                                                                                
                        parActivity pact = new parActivity();
                        List<Participant_Hours__c> phs = new List<Participant_Hours__c>();
                        Participant_Activity__c pa = new Participant_Activity__c();
                        pa.Start_Time__c = ph.Start_Time__c;
                        pa.End_Time__c = ph.End_Time__c;
                        pa.Case_Notes__c = ph.Case_Notes__c;
                        pa.Case__c = null;  // this is how we tell the page that these are not real PAs
                        pact.pa = pa;
                        pact.shs = null;
                        pact.shssize = 0;
                        pact.phssize = 0;
                        pact.num = o++;
                        phs.add(ph);
                        pact.phs = phs;
                        pact.phssize = 1;
                        activities.add(pact);           
                                        
        }
     }
     
     return activities;
 } 
 
 public Integer listSize {
        
        get {
                return activities.size();
        }
        
        set;}
 
 public PageReference LoadPDF() {

     //PageReference pdf = new PageReference('/apex/AssessmentViewPDF?id=' + AssessmentTaken.id);
     PageReference pdf = new Pagereference('/apex/CaseNotesViewPDF?id='+cid+'&starttime='+singlepa.Start_Time__c+'&endtime='+singlepa.End_Time__c);
     pdf.setRedirect(true);
     return pdf;
 }



 
Gururaj BGururaj B
you should use the "includes" clause when you are finding set of values in a multi-picklist field. So your query should be like below and the variable,"stractoff " should have the values seperated by ";"(semicolon). Mark as best answer if this helped you in any way.

[select id, Participant__c, Participant__r.DEM_Family_Role__c, Main_Participant__c, Duration__c, Service_Code__c, Bill_Code__c, 
                                                                                Case_Notes__c, Type__c, Start_Time__c, End_Time__c  
                                                                        from Participant_Hours__c
                                                                        where Case__c =: cid 
                                                                        and Group_Meeting__c != null
                                                                        and Start_Time__c>=:starttime 
                                                                        and Start_Time__c<=:endtime
                                                                        and Activities_Offered__c includes (:stractoff )
                                                                        order by Start_Time__c ]
Paul BrainardPaul Brainard
Thanks Gururaj!

I thought for sure that was the ticket.  When I added that change to stractoff, the PDF doesn't list any notes.  Can you see if there's any place I'm missing the stractoff reference?