Advertisement
Guest User

UserOnboardingValidationExtension

a guest
Jan 15th, 2017
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.75 KB | None | 0 0
  1. public class UserOnboardingValidationExtension {
  2.     /*This class is used with a visualforce page
  3.      * to validate that training exercises have been successfully completed
  4.      */
  5.    
  6.    
  7.     ID inputId = ApexPages.currentPage().getParameters().get('id');
  8.     transient User thisUser = new User();
  9.  
  10.     public Boolean hasCreatedChatterPost { get; set; }
  11.     public Boolean hasCreatedContact { get; set; }
  12.     public Boolean hasCreatedAccount { get; set; }
  13.     public Boolean hasCreatedSharedContact { get; set; }
  14.     public Boolean hasAddedPhoto { get; set; }
  15.     public Boolean hasAddedBio { get; set; }
  16.     public Boolean hasClosedTask { get; set; }
  17.     public Boolean completedStatus { get; set; }
  18.     public task completedTask {get; set;}
  19.     public Integer remainingTasks { get; set; }
  20.  
  21.     public User getUser() {
  22.         return thisUser;
  23.     }
  24.  
  25.     public UserOnboardingValidationExtension(ApexPages.StandardController stdController) {
  26.         calculateStatus();
  27.     }
  28.  
  29.     public void calculateStatus() {
  30.         IF(inputId == NULL){
  31.             thisUser = [SELECT FullPhotoUrl, SmallPhotoUrl, AboutMe, Name FROM User WHERE Id = :UserInfo.getUserId()];
  32.         }
  33.         ELSE {
  34.             thisUser = [SELECT FullPhotoUrl, SmallPhotoUrl, AboutMe, Name FROM User WHERE Id = :InputId];
  35.         }
  36.         hasCreatedChatterPost = [SELECT COUNT() FROM FeedItem WHERE InsertedById = :thisUser.Id LIMIT 1] == 1;
  37.         hasCreatedContact = [SELECT COUNT() FROM Contact WHERE CreatedById = :thisUser.Id LIMIT 1] == 1;
  38.         hasCreatedAccount = [SELECT COUNT() FROM Account WHERE CreatedById = :thisUser.Id LIMIT 1] == 1;
  39.         hasCreatedSharedContact = [SELECT COUNT() FROM ContactShare WHERE RowCause='Manual' AND ContactId IN (SELECT Id FROM Contact Where CreatedById =: thisuser.Id)  LIMIT 1] == 1;
  40.         hasAddedPhoto = thisUser.FullPhotoUrl != null && !thisUser.FullPhotoUrl.endsWith('/profilephoto/005/F');
  41.         hasAddedBio = thisUser.AboutMe != null;
  42.         hasClosedTask = [SELECT COUNT() FROM Task WHERE OwnerId =: thisUser.Id AND IsClosed = TRUE LIMIT 1] == 1;
  43.         IF(hasClosedTask == TRUE){
  44.         completedTask = [SELECT Id FROM Task WHERE OwnerId =: thisUser.Id AND IsClosed = TRUE LIMIT 1];
  45.         }
  46.         remainingTasks =
  47.             (hasCreatedChatterPost  ? 0: 1) + (hasCreatedContact        ? 0: 1) +
  48.             (hasCreatedAccount      ? 0: 1) + (hasCreatedSharedContact  ? 0: 1) +
  49.             (hasAddedPhoto          ? 0: 1) + (hasAddedBio              ? 0: 1) +
  50.             (hasClosedTask          ? 0: 1);
  51.         completedStatus = remainingTasks == 0;
  52.     }
  53.    
  54.     public pageReference refreshValues(){
  55.     PageReference pageRef = ApexPages.currentPage();
  56.     pageRef.setRedirect(true);
  57.     return pageRef;
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement