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

Run Code on First Login

Is there any way to have code run or go to a specific VF page when a user first logs into a new org?  Our application has certain settings, and we want to:


(1) Take them to a "Setup Wizard" page when they first login, and continue to do so on login until all the decisions have been made


(2) Preferably prevent them from accessing the rest of the app until those decisions have been made, though this may not be mandatory


(3) After the decisions have been made, no longer have the setup wizard appear, but the user can still navigate to it if they wish


Just a suggestion... 

Requirement (1):

First, create a checkbox field on the User object... call it Completed Setup. You will use this flag to determine if the user should be redirected to your Setup Wizard.

Next, create a simple apex page to redirect the user to the Setup Wizard. Call the page swRedirect, for example:

<apex:page> <script type="text/javascript"> function redirect() { var completed = {!$user.completed_setup__c}; if (completed == false) { top.location.replace("/apex/setupWizard"); } } window.onload=redirect; </script> </apex:page>

The above code uses javascript to process the redirection but you could just as well use the page action attribute and a custom controller.

This next part is a bit of a hack:

Create a custom Home Page Component of type HTML Area. The challenge here will be coming up with the component name! (you'll see why in a bit). For the Component Position, place it in the Narrow (Left) Column. Check the "Show HTML" box, and enter the following code...

<iframe src="/apex/swRedirect" frameBorder=0 width="100%" height=0></iframe>

... where swRedirect is the apex page you created. Click Save. Note the height of 0. Since the main function of this component is to redirect the user to your Setup Wizard, there's nothing to display! The only thing that will be visible is the name of the component (hence the naming challenge).

Next, add the custom component to your page layout and move the component to the lowest position in the narrow column. Click Save.

Now visit your home page, and watch the magic happen! :smileyvery-happy:

Requirement (2):

Click Setup > Customize > User Interface. Check the box marked "Show Custom Sidebar Components on All Pages". Your user will be redirected to the Setup Wizard no matter what page he/she navigates to!

Requirement (3):

As a last step in your setup wizard, make sure to set the Completed Setup flag on the user object. This will stop the redirection. If your users need to run the wizard again, instruct them to uncheck the Completed Setup box in their Personal Information.

Hope that helps!