You need to sign in to do that
Don't have an account?
Arvind_Chauhan
How to send alerts to users who haven't logged in for 60 days?
How can we send users an email notification automatically, who haven't logged into their Salesforce account for 60 days?
Label: User have not logged in
api name: User_have_not_logged_in__c
return type: number
formula: Today() - LastLoginDate
It will return the number of days since user have not logged in.
Write a class with the following logic:
List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
List<User> usrList= [SELECT Id, LastLoginDate, Email, User_have_not_logged_in__c Name FROM User where User_have_not_logged_in__c >60];
List<String> sendTo = new List<String>();
if(usrList.size()>0){
for(User u:usrList){
sendTo.add(u.Email);
}
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setSenderDisplayName('Email alert');
mail.setSubject('Owner change');
String body = 'Dear User, Its been more than 60 days, you have not logged in to the Org';
mail.setToAddresses(sendTo);
mail.setHtmlBody(body);
mails.add(mail);
try{
Messaging.sendEmail(mails);
}
catch(Exception e){
system.debug('-------------exception------'+e);
You schedule it using schedule apex if you want to run this class daily.
Hi Arvind_Chauhan,
Please find the solution. How to send alerts to users who haven't logged in for 60 days?
I hope it would work.
Please mark best soltuion so that other people would take reference from it.
Thanks