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
Becky Miller 15Becky Miller 15 

Invalid bind expression type

**Still Learning**
I am trying to create the Apex Controller that will then be used by the Visualforce page for layouts.  I only want to show the Current Fiscal Period based on Todays date on the Visualforce page.  

Period_FY__c is just a formula field that is a String:  Below is the code for the formula field.
CASE( 
Text(Month(TODAY() )) , 
"1","2", 
"2","3", 
"3","3", 
"4","3", 
"5","4", 
"6","4", 
"7","4", 
"8","1", 
"9","1", 
"10","1", 
"11","2", 
"12","2", 
"" 
)

The code where I am having an error.  If there is a different way this would be written better I am open. (learning)

public with sharing class QuotaRelatedListqtr {

public List <Quota__c> quotas {get;set;}
public List <Business_Plan__c> bp {get;set;}
public List <Period> period {get;set;}
    
Integer FiscalYearStartMonth = 
[select FiscalYearStartMonth from Organization where id=:Userinfo.getOrganizationId()].FiscalYearStartMonth;

String TodaysDate = date.today().format();
     
Public List <Period> Periods = [Select p.Number From Period p 
         Where (p.StartDate <= TODAY AND p.EndDate >= TODAY) and p.type = 'Quarter' Limit 1];


       // Get information about the Quota being worked on
       // Needs to be based on Business Plan per Person 
       // Need to get the correct FY and Correct Quarter based on todays date.    
       // 
public QuotaRelatedListqtr(ApexPages.StandardController controller) {
 quotas = [SELECT Actual_Sales__c, Actual_vs_Quota__c, Annual_Actual_Sales__c, Annual_Quota__c, 
                           Annual_Targeted_New_Business_Sales__c, Business_Plan__c, Fiscal_Period2__c,
                               Quota__c, Sales_Categories__c, Sales_Category_Name__c,  Sales_Needed_to_Hit_Quota__c,Sales_Product_Category__c,
                               Sales_Won__c, Targeted_New_Business__c,Target_vs_Quota__c,Targeted_New_Business_Sales__c
                               FROM Quota__c
                              WHERE Period_FY__c IN :Periods];    
                             
    }
              
}


Here is the Error Message:  Invalid bind expression type of Period for column of type String
I have bolded the line where it is saying the error is.

 
Best Answer chosen by Becky Miller 15
Nayana KNayana K
Please Change 
if(!lstPeriods.isEmpty())
{
strFY = String.valueOf(lstPeriod[0].Number);
}

to
if(!Periods.isEmpty())
{
strFY = String.valueOf(Periods[0].Number);
}

All Answers

Nayana KNayana K
public with sharing class QuotaRelatedListqtr {

public List <Quota__c> quotas {get;set;}
public List <Business_Plan__c> bp {get;set;}
public List <Period> period {get;set;}
    
Integer FiscalYearStartMonth = 
[select FiscalYearStartMonth from Organization where id=:Userinfo.getOrganizationId()].FiscalYearStartMonth;

String TodaysDate = date.today().format();
     
Public List <Period> Periods = [Select p.Number From Period p 
         Where (p.StartDate <= TODAY AND p.EndDate >= TODAY) and p.type = 'Quarter' Limit 1];


       // Get information about the Quota being worked on
       // Needs to be based on Business Plan per Person 
       // Need to get the correct FY and Correct Quarter based on todays date.    
       // 
public QuotaRelatedListqtr(ApexPages.StandardController controller) {
String strFY = '';
if(!lstPeriods.isEmpty())
{
/* you have applied LIMIT 1 which means only one record will be retrieved */
strFY = String.valueOf(lstPeriod[0].Number); 
}
 quotas = [SELECT Actual_Sales__c, Actual_vs_Quota__c, Annual_Actual_Sales__c, Annual_Quota__c, 
                           Annual_Targeted_New_Business_Sales__c, Business_Plan__c, Fiscal_Period2__c,
                               Quota__c, Sales_Categories__c, Sales_Category_Name__c,  Sales_Needed_to_Hit_Quota__c,Sales_Product_Category__c,
                               Sales_Won__c, Targeted_New_Business__c,Target_vs_Quota__c,Targeted_New_Business_Sales__c
                               FROM Quota__c
                              WHERE Period_FY__c =: strFY];    
                             
    }
              
}

 
James LoghryJames Loghry
Hi Becky,

SOQL only supports primitives or collections of primitives for variable binding. Primitives are simple types like integer, boolean, and strings. In your case, Periods is a list of custom objects. Hence, why the compiler no likey.

You'll need to loop through the array of periods and dig out all the strings you need.

Here's an example:
 
public QuotaRelatedListqtr(ApexPages.StandardController controller) {
    Set<String> periodNumbers = new Set<String>();
    for(Period p : [Select Number From Period Where StartDate <= TODAY and EndDate >= TODAY and Type = 'Quarter' Limit 1]){
        periodNumbers.add(p.Number);
    }

     quotas =
         [Select 
               Actual_Sales__c,
               Actual_vs_Quota__c,
               Annual_Actual_Sales__c,
               Annual_Quota__c, 
               Annual_Targeted_New_Business_Sales__c,
               Business_Plan__c,
               Fiscal_Period2__c,
               Quota__c,
               Sales_Categories__c,
               Sales_Category_Name__c,
               Sales_Needed_to_Hit_Quota__c,
               Sales_Product_Category__c,
               Sales_Won__c,
               Targeted_New_Business__c,
               Target_vs_Quota__c,
               Targeted_New_Business_Sales__c
           From 
               Quota__c
           Where 
               Period_FY__c IN :periodNumbers];
}
 
Becky Miller 15Becky Miller 15
Hi James --- 

Unexpected token 'QuotaRelatedListqtr'.

I am confused what the error means.
Nayana KNayana K
Please Change 
if(!lstPeriods.isEmpty())
{
strFY = String.valueOf(lstPeriod[0].Number);
}

to
if(!Periods.isEmpty())
{
strFY = String.valueOf(Periods[0].Number);
}
This was selected as the best answer
Peter GruhlPeter Gruhl
Hi Becky,

A question while I try to fully understand your requirements.  If you just want to show the current fiscal period, is there a reason why you don't just use the built-in fiscal periods of the SOQL WHERE clause?  For example, on your query, you could add a WHERE clause like:

WHERE myDate = THIS_FISCAL_QUARTER);

There are other options for calendar & fiscal weeks, months, years, etc.  More  info is available in SOSL & SOQL reference document, around page 97.
Becky Miller 15Becky Miller 15
Thank you everyones help.  I got it working with THIS FISCAL QUARTER and also bits and pieces of the code above.