Created
January 31, 2016 06:54
-
-
Save keirbowden/b9a7d75b685e2d86493e to your computer and use it in GitHub Desktop.
Lightning Component Apex Controller for the User Freezer Blog Post
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** ***************************************************************************** | |
* 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