workflow rule to alert when someone hasn't logged in after x amount of days - Answers - Salesforce Trailblazer Community
Trailblazer Community
Ask Search:
Katie DeLunaKatie DeLuna 

workflow rule to alert when someone hasn't logged in after x amount of days

Hello to my favorite people!

Maybe I have the case of the Mondays, but I'm trying to do two things -

1. Create a workflow rule that will alert a user when someone hasn't logged in for 80 days. I can't seem to think of how to enter that criteria in the workflow rule!
2. Similarly, I'm trying to create a report that generates a list of users who haven't logged in after 90 days.

How can I get that time frame criteria to populate correctly? Whatever I'm doing isn't working!
Steve MolisSteve Molis
User Last Login Date can't be accessed via a WFR, you might be better off creating a Report and either schedule it to run automatically or use Report Subscriptions => 
https://help.salesforce.com/HTViewHelpDoc?id=reports_notifications_home.htm&language=en_US (https://help.salesforce.com/HTViewHelpDoc?id=reports_notifications_home.htm&language=en_US)
 

Yopu might also be able to do something like what you described using the Process Builder instead of a WFR
 
Katie DeLunaKatie DeLuna
We actually have last login date available as a field in the workflow rule and in the report. Someone must have added it (we have a consulting firm who occassionally does back end work). I just cant figure out how to get the data to display correctly....
Katie DeLunaKatie DeLuna
User-added imageUser-added image
Steve MolisSteve Molis
I just threw this together using the Process Builder and the standard User.LastLoginDate field 

User-added image
Steve MolisSteve Molis
You're right it is in there (note to self: Keep up with SFDC Release Notes) 

The only thing that worries me is that you need an "edit" to trigger a WFR, and since Last Login Date is not the same as Last Modified Date I don't think logging in is "enough of an Edit" to trigger or reset the WFR 
Katie DeLunaKatie DeLuna
i've never heard of process builder. does it do the same thing as a workflow rule essentially??
Katie DeLunaKatie DeLuna
This process builder looks amazing!!!!!!!!!!!!!!!
Steve MolisSteve Molis
Yeah, there's a lot of overlap.  The Process Builder is kinda "where things are going" it's kinda like parts of WFR+VisualFlow+Publisher Actions all in one App/Tool.  It takes some getting used to, and trial and error, but you can do some stuff that used to be impossible without Apex like "Create a new record when (A+B) = C..." 
Katie DeLunaKatie DeLuna
Yeah! I need to get this done by the end of the week. This is the criteria I’m working off of: • We will review and create automation alerting users and their managers that their licenses will be deactivated due to inactivity. We will do a time based alert 10 days before deactivation. • We will create an automated report to Sys Admin team whenever a license has met the 90 threshold and deactivate the licenses • We will create cases for deactivated licenses for tracking purposes.
Katie DeLunaKatie DeLuna
still having problems with how to enter the conditions :(
User-added image
Steve MolisSteve Molis
Okay, I think you want "No criteria - just execute the Action" then set the Action to 80 Day after Last Login.
Katie DeLunaKatie DeLuna
STEVEMO, you're my hero!!!!!!!!!!!!!!!!! >insert real life beer<
Katie DeLunaKatie DeLuna
Great, now trying to create the email alert. I created the email template, but now i need to ensure that the correct user and their manager (the manager is a custom field on the user record) get notified. Any ideas?
Katie DeLunaKatie DeLuna
User-added image
Steve MolisSteve Molis
Schiesse....  I can only get my trigger to work if I edit the User Detail record >:-( 
Katie DeLunaKatie DeLuna
How can I auto-populate an email address when someone enters a user email on the user record? For instance, we have a lookup field on the user record that says "Manager". So, I created an email field called "Manager's Email". Then, created a workflow rule to populate the email: 

Evaluation Criteria Evaluate the rule when a record is created, and any time it’s edited to subsequently meet criteria

NOT(ISBLANK(Manager_Email__c))

then immediately --

Field Update - Field to Update User: Manager Email: Formula Value Manager.Email

It's not working! I thought that by creating another email field on the user record, i could also copy the user's manager on the email alert (it has to be in email format,,as i'm sure you know)

 
Steve MolisSteve Molis
*sigh*  Sorry to drag you down a Rat Hole with me.  At least the Report is doable, so I got that goin't for me, which is nice...
User-added image
Katie DeLunaKatie DeLuna
So you're thinking process builder isn't gonna work? I know management wants alerts and notifications because we'll start to deactivate users and we want to give users a change to login before we deactivate them :(
Katie DeLunaKatie DeLuna
I don't want to give up! don't give up on me! hahaha

User-added image
Steve MolisSteve Molis
Lemme take a step back from the ledge/cliff, maybe I'm just under-thinking and over-complicating this.   
Katie DeLunaKatie DeLuna
i'm also gonna change the criteria for testing purposes to be half hour and an hour. 
 
Katie DeLunaKatie DeLuna
i KNOW im under thinking and over complicating this! plus, this is new to me!
Narsimha RaoNarsimha Rao
Hello Katie,

Did you ever get a solution using workflow or process builder for your requirement? As far as I know, the only solution for your requirement is code. I have the very similar requirement now and the only way I could think is code. Because, for the workflow or process builder to fire, there should be an action on the user record. And since there is no way we could cause an action on the user record, we couldn't use the workflow or process builder. But again, I have seen people come up with some cool tricks to do some impossible things on Salesforce. So, if you found a solution, please post here.

Thanks
Narsimha Rao 
Narsimha RaoNarsimha Rao
BTW, here is the code I used:
global class BatchtoSendEmailstoUser implements Database.Batchable<sobject>{
    Date tdate = System.today() - 37;  
    Map<Id,Profile> profileIds = new Map<id,profile>([SELECT Id,UserLicenseId FROM Profile where UserLicenseId  in (SELECT Id FROM UserLicense where name ='Salesforce')]);
    List<User> userIds = [SELECT Id FROM User WHERE profileId in:profileIds.Keyset() AND IsActive=True AND LastLoginDate = :tdate];
    
    public String query = 'SELECT Id FROM User WHERE Id IN :userIds';
    
    global Database.QueryLocator start(Database.BatchableContext bc){
        return Database.getQueryLocator(query);
    }
    
    global void execute(Database.BatchableContext bc, LIST<sobject> InactiveUsers) {
        
        EmailTemplate emailTemplate = [select Id, Body  from EmailTemplate where DeveloperName = 'Freeze_warning_to_Users'];
        for(Sobject user:InactiveUsers){
            User user2 = (User)user;
            Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
            email.setToAddresses(new String[] {user2.Email});
            email.setSaveAsActivity(false);
            email.setTargetObjectId(user2.Id);
            email.setTemplateId(emailTemplate.Id);
            email.setWhatId(user2.Id);
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});            
        }        
    }
    
    global void finish(Database.BatchableContext FreezeWarningtoUsers) {}
    
}