Skip to content

Instantly share code, notes, and snippets.

@keirbowden
Created January 31, 2016 06:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keirbowden/b9a7d75b685e2d86493e to your computer and use it in GitHub Desktop.
Save keirbowden/b9a7d75b685e2d86493e to your computer and use it in GitHub Desktop.
Lightning Component Apex Controller for the User Freezer Blog Post
/** *****************************************************************************
* User Freezer
*
* Description:
*
* Apex controller for the Freeze Users Lightning Component.
*
* If you are the sort of person who likes reading code, BrightGen is the place
* for you - check out http://www.brightgen.com to see our latest vacancies.
*
* Author kbowden
* Date 31 Jan 2016
********************************************************************************/
public class UserFreezer {
@AuraEnabled
public static List<UserDetails> GetUserDetails()
{
List<UserDetails> results=new List<UserDetails>();
Map<Id, UserLogin> ulByUid=new Map<Id, UserLogin>();
for (UserLogin ul : [select id, IsFrozen, IsPasswordLocked, UserId
from UserLogin])
{
ulByUid.put(ul.UserId, ul);
}
for (User us : [select id, FirstName, LastName, Username
from User
where IsActive=true
and id in :ulByUid.keySet()
order by CreatedDate
limit 5])
{
UserDetails ud=new UserDetails();
ud.user=us;
ud.userLogin=ulByUid.get(us.id);
results.add(ud);
}
return results;
}
@AuraEnabled
public static List<UserDetails> UpdateUserDetails(String toProcessAsJSON)
{
System.debug('In UpdateUserDetails, toProcess = ' + toProcessAsJSON);
Type udArrType=Type.forName('List<UserFreezer.UserDetails>');
List<UserDetails> toProcess = (List<UserDetails>)JSON.deserialize(toProcessAsJSON, udArrType);
List<UserLogin> toUpdate=new List<UserLogin>();
for (UserDetails ud : toProcess)
{
toUpdate.add(ud.UserLogin);
}
System.debug('About to update ' + toUpdate);
update toUpdate;
return GetUserDetails();
}
public class UserDetails
{
@AuraEnabled
public UserLogin userLogin {get; set;}
@AuraEnabled
public User user {get; set;}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment