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
jimc507jimc507 

Setting Login Hours programmatically

Hello,


After  SFDC does an upgrade on an org, we need the ability to lockout users from using SFDC until we have gone through our regression testing. Once the testing is done we need to remove the login restrictions and allow access to SFDC. Currently, to accomplish the task, we set the Login Hours for each profile to lockout the time we need to test. However, we currently have over 75 profiles, so this task becomes very tedious and time consuming. Is there a way to set the Login Hours via APEX or the SFDC API using the Data Loader? 

 

Thanks in advance,

Jim

jeff.isomjeff.isom

I discovered just recently that you can deploy a sparse profile object using the Ant Migration tool to set login-hours.

 

If you create a .profile that looks like this:

 

<?xml version="1.0" encoding="UTF-8"?>
<Profile xmlns="http://soap.sforce.com/2006/04/metadata">
	<loginHours>
		<wednesdayEnd>1080</wednesdayEnd>
		<wednesdayStart>0</wednesdayStart>
	</loginHours>
	<userLicense>Salesforce</userLicense>
</Profile>

 and deploy using the ant tool.  The number is the number of minutes since midnight.  In this case login hours are from midnight to 6 pm (18 * 60 = 1080)

 

Then to unset the hours you can deploy an even sparser profile that looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<Profile xmlns="http://soap.sforce.com/2006/04/metadata">
	<loginHours>
	</loginHours>
	<userLicense>Salesforce</userLicense>
</Profile>

 

Hope this helps.