You need to sign in to do that
Don't have an account?
Felipe Senler
For loop that gets all users from User, to get certain users from User
Hello community:
You see, i have this issue from a previous problem on another post though, since ive upgraded my solution a bit more, but heres my issue:
I need that from a for loop on two users, user1 (Original object) and User2 object to dinamically itarate against, to get all users, this actually does manage to grant me all users from the Object user, but now i need to get only a few names out of it, heres the code ive figured so far:
Any help is appreciated.
You see, i have this issue from a previous problem on another post though, since ive upgraded my solution a bit more, but heres my issue:
I need that from a for loop on two users, user1 (Original object) and User2 object to dinamically itarate against, to get all users, this actually does manage to grant me all users from the Object user, but now i need to get only a few names out of it, heres the code ive figured so far:
for(User user2:user1)//Iterates to get all users available { String usua = user2.name; System.debug('Nombres de usuarios:'+usua); String usuaid = user2.id;//gets the id for each user retrieved String a = usuaid; //Assigns the Id of the users into 'a' as variable (Orginal,right?) Id usuarioid = Id.valueOf(a);//turns the id (String) as Id System.debug('Id usuario: '+usuarioid); }To sum up, i need to basically, from this loop that gets me all users and id's from user to be able to retrieve certain users out of it, been trying to figure this out, but im kinda stuck for the time being.
Any help is appreciated.
I do have a question about the approach of this code, from my understanding the user1 object is gathering all users in your org via an for loop. A second for loop was created to search for a particular set of users. My question is this, just create a Map against the User object and add a SOQL where clause to limit the search for the records you are looking for? With this approach, you will have your users stored in a variable that you can manipulate at your lesuire within the code. Here is an example of this function: https://developer.salesforce.com/page/Apex_Code_Best_Practices
Thanks a lot for your fast reply.