public class trigger36 {
public static void trigger1(List<Account> accList)
{
Set<id> accId = new Set<id>();
List<Account> Listoppos = new List<Account>();
Map<id,List<Opportunity>> MapacOp = new Map<id,List<Opportunity>>();
List<Opportunity> updated = new List<Opportunity>();
for(Account a : accList)
{
accId.add(a.id);// fetch id of all accounts which were updated
}
Listoppos = [select Id, (Select name,StageName,CreatedDate from Opportunities) from Account where ID IN: accId];
for(Account a :Listoppos)
{
MapacOp.put(a.id, a.opportunities);
}
for(Id i: accId)
{
List<Opportunity> x = MapacOp.get(i);
for(opportunity xx:x)
{
if(xx.StageName != 'ClosedWon' && System.Today() - 30 > xx.CreatedDate.date())
{
xx.StageName ='Closed Lost';
updated.add(xx);
}
}
if(updated.size() > 0)
{
update updated;
}
}
}
}
I am trying to write a trigger which changes the opportunity StageName as per the conditions: Update all Opportunities Stage to close lost if an opportunity created date is greater than 30 days from today and stage not equal to close won.
My code seems to be working fine but I wish to understand why
System.Today() - 30 > xx.CreatedDate.date()
seems to be working fine but
System.Today() - xx.CreatedDate.date() > 30
seems to fire an error,
Date expressions must use Integer or Long
What exactly is this error trying to imply?
PS. xx is an Opportunity
object and x is list<Opportunity>
.