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
Blake TanonBlake Tanon 

Issue with variables in subquery in WHERE clause (Class)

I"ve been racking my brain over this for a while so it's time to ask for some help.  I'm tring to query a list in a Class to display on a VF page, but when I put a variable into the SubQuery in the Where clause I don't get any results, however if i just put in a record ID it works.  

 

global class DistributionExtentionRepMonthlyReport_C{

public static list<contact> cList;


    public DistributionExtentionRepMonthlyReport_C(){
    //public void runQuery(){
        
            cList = [SELECT id, FirstName, LastName, OtherStreet, OtherCity, OtherState, OtherPostalCode,
                         Account.Name, CRD__c
                     FROM contact
                     WHERE id in (SELECT rep__c
                                  FROM distribution_history__c
                                  WHERE distribution__c =: ApexPages.currentPage().getParameters().get('id'))
                     LIMIT 50];


    }

    public static list<contact> getcList(){
        return clist;
    }


}

 

Avidev9Avidev9

How about debugging the code ?

 

global class DistributionExtentionRepMonthlyReport_C{

public static list<contact> cList;


    public DistributionExtentionRepMonthlyReport_C(){
    //public void runQuery(){
            String idParam = ApexPages.currentPage().getParameters().get('id');
System.debug('#########idParam########'+idParam);
cList = [SELECT id, FirstName, LastName, OtherStreet, OtherCity, OtherState, OtherPostalCode, Account.Name, CRD__c FROM contact WHERE id in (SELECT rep__c FROM distribution_history__c WHERE distribution__c =:idParam ) LIMIT 50]; } public static list<contact> getcList(){ return clist; } }

 Create and check the debug log if you are getting the expected value.

 

By the way you need to pass the id to the VF page by doing something like "/apex/YOUR_VF_PAGE_NAME?id=RECORD_ID"