You need to sign in to do that
Don't have an account?
Jon-Michael Murphey
Unexpected Token on setting Datetime Variable
I have a schedule apex that deactivates users after 90 days since last login, the apex failed on run because of an Unexpected token error on the following: First error: unexpected token: 'dt'
Please review the snippit below:
dateTime dt = date.today()-90;
public String query = 'SELECT Name, LastLoginDate, Id From User WHERE IsActive = true AND LastLoginDate < +dt and profile<>"System Adminstrator" ';
Please review the snippit below:
dateTime dt = date.today()-90;
public String query = 'SELECT Name, LastLoginDate, Id From User WHERE IsActive = true AND LastLoginDate < +dt and profile<>"System Adminstrator" ';
Try this code:-
date dt=System.today().addDays(-90);
String query = 'SELECT Name, LastLoginDate, Id From User WHERE IsActive = true AND LastLoginDate<dt and profile<>"System Adminstrator" ';
Thanks
Anil.B
Hi Jon,
Try this:
date dt=System.today().addDays(-90);
String query = 'SELECT Name, LastLoginDate, Id From User WHERE IsActive = true AND LastLoginDate<:dt and profile<>"System Adminstrator" ';
Or you can also write your query as
date dt=System.today().addDays(-90);
String query = 'SELECT Name, LastLoginDate, Id From User WHERE IsActive = true AND LastLoginDate<'+dt+' and profile<>"System Adminstrator" ';
Which ever suits your requirement better.
Let me know if it helps.
Thanks.
That didnt work it threw a new error: First error: expecting a colon, found 'dt'