document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. //Apex class to generate the list of user assigned to a profile
  2.  
  3. List<User> lUser = [SELECT Id , ProfileId from User ];  // list of users
  4. List<Profile> lProfile = [SELECT Id, ProfileID from Profile];
  5. List<Profile> noUserProfile = [SELECT id, ProfileId from Profile];
  6.  
  7. for(Profile p : lProfile)
  8. {
  9.  
  10. //iterate and figure out fill up the corresponding list
  11. bool flag= false;
  12.  
  13. for(User u : lUser)
  14. {
  15.  if(profileId ==p.id)
  16.    flag=true;
  17. }
  18. if(!flag)   //whenever the flag is true
  19. noUserProfile.add(p);  //add this profile to nouserprofile list
  20.  
  21. }     //end of iteration for profile list
  22.  
  23.  
  24. System.debug(\'profileWithNoUser ::: \' + profileWithNoUser + \' ::: \' + profileWithNoUser.size() ) ;
  25.  
  26. }
');