Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class UserOnboardingValidationExtension {
- /*This class is used with a visualforce page
- * to validate that training exercises have been successfully completed
- */
- ID inputId = ApexPages.currentPage().getParameters().get('id');
- transient User thisUser = new User();
- public Boolean hasCreatedChatterPost { get; set; }
- public Boolean hasCreatedContact { get; set; }
- public Boolean hasCreatedAccount { get; set; }
- public Boolean hasCreatedSharedContact { get; set; }
- public Boolean hasAddedPhoto { get; set; }
- public Boolean hasAddedBio { get; set; }
- public Boolean hasClosedTask { get; set; }
- public Boolean completedStatus { get; set; }
- public task completedTask {get; set;}
- public Integer remainingTasks { get; set; }
- public User getUser() {
- return thisUser;
- }
- public UserOnboardingValidationExtension(ApexPages.StandardController stdController) {
- calculateStatus();
- }
- public void calculateStatus() {
- IF(inputId == NULL){
- thisUser = [SELECT FullPhotoUrl, SmallPhotoUrl, AboutMe, Name FROM User WHERE Id = :UserInfo.getUserId()];
- }
- ELSE {
- thisUser = [SELECT FullPhotoUrl, SmallPhotoUrl, AboutMe, Name FROM User WHERE Id = :InputId];
- }
- hasCreatedChatterPost = [SELECT COUNT() FROM FeedItem WHERE InsertedById = :thisUser.Id LIMIT 1] == 1;
- hasCreatedContact = [SELECT COUNT() FROM Contact WHERE CreatedById = :thisUser.Id LIMIT 1] == 1;
- hasCreatedAccount = [SELECT COUNT() FROM Account WHERE CreatedById = :thisUser.Id LIMIT 1] == 1;
- hasCreatedSharedContact = [SELECT COUNT() FROM ContactShare WHERE RowCause='Manual' AND ContactId IN (SELECT Id FROM Contact Where CreatedById =: thisuser.Id) LIMIT 1] == 1;
- hasAddedPhoto = thisUser.FullPhotoUrl != null && !thisUser.FullPhotoUrl.endsWith('/profilephoto/005/F');
- hasAddedBio = thisUser.AboutMe != null;
- hasClosedTask = [SELECT COUNT() FROM Task WHERE OwnerId =: thisUser.Id AND IsClosed = TRUE LIMIT 1] == 1;
- IF(hasClosedTask == TRUE){
- completedTask = [SELECT Id FROM Task WHERE OwnerId =: thisUser.Id AND IsClosed = TRUE LIMIT 1];
- }
- remainingTasks =
- (hasCreatedChatterPost ? 0: 1) + (hasCreatedContact ? 0: 1) +
- (hasCreatedAccount ? 0: 1) + (hasCreatedSharedContact ? 0: 1) +
- (hasAddedPhoto ? 0: 1) + (hasAddedBio ? 0: 1) +
- (hasClosedTask ? 0: 1);
- completedStatus = remainingTasks == 0;
- }
- public pageReference refreshValues(){
- PageReference pageRef = ApexPages.currentPage();
- pageRef.setRedirect(true);
- return pageRef;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement