Skip to content

Instantly share code, notes, and snippets.

@keirbowden
Created November 3, 2013 17:58
Show Gist options
  • Save keirbowden/7292906 to your computer and use it in GitHub Desktop.
Save keirbowden/7292906 to your computer and use it in GitHub Desktop.
The Freezer - Visualforce page to allow users to be frozen or defrosted
<apex:page >
<script type="text/javascript">
var __sfdcSessionId = '{!GETSESSIONID()}';
</script>
<script src="../../soap/ajax/29.0/connection.js"
type="text/javascript"></script>
<script type="text/javascript">
function getUserInfo()
{
var userInfoById = {};
var result = sforce.connection.query(
"Select Id, UserId, IsFrozen, IsPasswordLocked From UserLogin order by UserId");
var it = new sforce.QueryResultIterator(result);
while(it.hasNext())
{
var record = it.next();
userInfoById[record.UserId] = record;
}
var output='<table><tr><th>User</th><th>Action</th></tr>';
result = sforce.connection.query(
"Select Id, FirstName, LastName from User where IsActive=true");
it = new sforce.QueryResultIterator(result);
while(it.hasNext())
{
var record = it.next();
if (record.Id in userInfoById)
{
var userInfo=userInfoById[record.Id];
var name=record.FirstName + ' ' + record.LastName;
output+='<tr><td>' + name + '</td><td>';
if (userInfo.IsFrozen=='true')
{
output+="<button onclick=\"freeze('" + userInfo.Id + "', '" + name + "', false);\">Defrost</button>";
}
else
{
output+="<button onclick=\"freeze('" + userInfo.Id + "', '" + name + "', true);\">Freeze</button>";
}
output+='</td></tr>';
}
}
output+='</table>';
document.getElementById('output').innerHTML=output;
}
function freeze(id, name, freezerState)
{
alert("Freezing " + name);
var userlogin = new sforce.SObject("UserLogin");
userlogin.Id = id;
userlogin.IsFrozen = freezerState;
var result = sforce.connection.update([userlogin]);
if (result[0].getBoolean("success")) {
alert(name + " " + (freezerState?'frozen':'defrosted'));
} else {
alert("failed to " + name + " " + result[0]);
}
window.location.reload();
}
</script>
<apex:sectionHeader title="The Freezer"/>
<div id="output"> </div>
<script>
getUserInfo();
</script>
</apex:page>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment