You need to sign in to do that
Don't have an account?
Becky 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.
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.
if(!lstPeriods.isEmpty())
{
strFY = String.valueOf(lstPeriod[0].Number);
}
to
if(!Periods.isEmpty())
{
strFY = String.valueOf(Periods[0].Number);
}
All Answers
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:
Unexpected token 'QuotaRelatedListqtr'.
I am confused what the error means.
if(!lstPeriods.isEmpty())
{
strFY = String.valueOf(lstPeriod[0].Number);
}
to
if(!Periods.isEmpty())
{
strFY = String.valueOf(Periods[0].Number);
}
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.