function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Zack ThomasZack Thomas 

Run code at login

I'm attempting to run code when a user logs in to check for overdue opportunities and then create a task and reminder to let the user know. My first thought was to create a trigger on the User object and check for differences in the LastLoginDate field, but this doesn't seem to work. I can see the field updating as it should, and the trigger runs and checks when doing an explicit update to user fields through Setup, but nothing seems to get run on login.

 

Any ideas? 

JonPJonP

There's no login event that you can use to run backend code.

 

Rather than going through a convoluted event > trigger > task path, what if you created a custom Visualforce home page that just queries and displays a list of overdue opportunities?

Zack ThomasZack Thomas
How does one go about replacing the home page with a custom Visualforce page?
JonPJonP

I misspoke a bit, but the general idea still holds.  You can't change the Home tab, but you can use your Visualforce page as the default tab in place of Home:

 

1. Create a Visualforce page

2. Create a custom Visualforce Tab for that page

3. Edit your App(s) to (a) add the new tab and (b) set the tab as the Default Landing Tab

 

When users log in, they will see your new tab first (but the existing Home tab will still be available).

Zack ThomasZack Thomas
Ah, makes more sense. I'll propose that, but my gut feeling is that it's not gonna fly. I think the admin is looking for something that gets in their face to let them know they have these items overdue.
David VPDavid VP

You can always create a homepage component that iframes a 0-pixel vf page which does the check in the underlying controller. Depending on the outcome that first VF page could then conditionally render some javascript window.open magic that would pop up a second VF page which would actually show the items you want.

 

That way everybody will be happy, including your admin :smileyhappy:

 

D.

Zack ThomasZack Thomas
Totally hax idea, but it works. Do you know of any way I can also hide the name of the home page component?