I need to get the user data who did not logged to system for last 30 days from a specific Date. Do you know how we can create a query for that? If you have any suggestions pls let me know.
Thanks
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.
Sign up to join this communityI need to get the user data who did not logged to system for last 30 days from a specific Date. Do you know how we can create a query for that? If you have any suggestions pls let me know.
Thanks
Not sure about literals ( can't see anything in the docs ).
However you can achieve this using the next code :
Date endInterval = Date.newInstance(2023, 1, 10);
Date startInterval = endInterval.addDays(-30);
List<Contact> conList = [Select Id,LastModifiedDate
From Contact
Where LastModifiedDate >: startInterval
and LastModifiedDate <: endInterval ] ;
Depends on your needs you can include/exclude the first and the last day in the interval!
Here's a SOQL query that will return Users who have not logged in the last 30 days:
SELECT Id, Name, LastLoginDate
FROM User
WHERE LastLoginDate < LAST_N_DAYS:30
The more literal way to describe the above query is to say that it will only return Users whose last login date occurred more than 30 days ago.
You can also use the following SOQL query to return any Users who have not logged in between two specified dates:
SELECT Id, Name, LastLoginDate
FROM User
WHERE Id NOT IN (SELECT UserId
FROM LoginHistory
WHERE LoginTime > 2023-01-15T00:00:00.000+0000
AND LoginTime < 2023-01-31T23:59:59.000+0000
)