You need to sign in to do that
Don't have an account?

Compile Error: unexpected token: '<' in date comparison
Here's a snippet of my code where I'm getting this error:
I'm getting the error on the {if(o.CloseDate < :Date.valueOf('2011-01-01') snippet. How can I do a date comparison without the < ?
Thank you!!
for(List<Opportunity> opportunities : [Select Id from Opportunity]) {for(Opportunity o : opportunities) {if(o.CloseDate < :Date.valueOf('2011-01-01') && o.StageName = 'Received');}} Map<Id, Opportunity> opportunitiesById = new Map<Id, Opportunity>(opportunities);
I'm getting the error on the {if(o.CloseDate < :Date.valueOf('2011-01-01') snippet. How can I do a date comparison without the < ?
Thank you!!
There is no : before Data.ValueOf. The sign : is only used in query when you want to use external variable.
for(List<Opportunity> opportunities : [Select Id, CloseDate, StageName, from Opportunity])
{for(Opportunity o : opportunities)
{if(o.CloseDate < Date.valueOf('2011-01-01') && o.StageName == 'Received');}}
Map<Id, Opportunity> opportunitiesById = new Map<Id, Opportunity>(opportunities);
All Answers
You don't need the : before date.Valueof, you try also to test stagename, it will require a == and not only =.
To test you must use ==, to affect a value it's =
Here a quick sample.
for(Opportunity o : [Select Id, CloseDate, StageName from Opportunity])
{
if(o.CloseDate < Date.valueOf('2011-01-01') && o.StageName == 'Received')
{
// Do something
}
}
But I'm still getting the error with the '<' sign.
There is no : before Data.ValueOf. The sign : is only used in query when you want to use external variable.
for(List<Opportunity> opportunities : [Select Id, CloseDate, StageName, from Opportunity])
{for(Opportunity o : opportunities)
{if(o.CloseDate < Date.valueOf('2011-01-01') && o.StageName == 'Received');}}
Map<Id, Opportunity> opportunitiesById = new Map<Id, Opportunity>(opportunities);