You need to sign in to do that
Don't have an account?
djain
Compare year in where clause in SOQL
Hi all,
In my application i require to fetch data for the year entered by user using SOQL query,
In SOQL i tried the below code:
Code:
date sampleDate=Date.today();
//assume user have entered 2003 Integer diff=sampleDate.year()-2003; Contact_log__c[] contactLog=[Select a.Id from Contact_log__c a where a.Last_Import_ModifiedDate__c =(THIS_YEAR-:diff) order by a.Sequence_Number__c desc limit 1];
but i get syntax error , Please guide me.
Thanks in advance
http://community.salesforce.com/sforce/board/message?board.id=general_development&message.id=11642
Jeff Douglas
Informa Plc
http://blog.jeffdouglas.com
Hi,
You could try something like this:
You can actually use:
where CALENDAR_YEAR(a.Last_Import_ModifiedDate__c) = (THIS_YEAR-:diff)
I am new to Salesforce, I am accessing sales force data trough another tool and writing a select query to pull out data for last two years but I am getting error and below is the query:
select
Account.Name,
RecordType.Name,
Opportunity.Effective_Date__c
from
Opportunity where
CALENDAR_YEAR(Opportunity.Effective_Date__c)>=:(THIS_YEAR -:2)
Please suggest, at any point of time, I need to pull 2 years data starting from Jan 1st like if am in November 2017, I need to pull data from Jan 2015.
I get syntax error "Bind Variables Allowed in Apex Code"
You can't compare the result of a date function with a date literal in a WHERE clause. You can refer this https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_date_functions.htm
Thanks