1

So I'm new to Sales force and I was recently given a requirement to populate a field in a my Sampling_c object from my RSM_c field which is in my User Object. This seems very straight forward but I wanted to double check my logic. So my thinking was

-Populate a userMap with the current users information with all the required information. So my question is how do I do that without populating the map with every single user in my User Object. I'll post my current code.

trigger SampleRVBAutoPop on Sampling__c (before insert,after update) {
//Generating User data.
user Users;
Map<String, User> userMap = new Map<String, User>();
List<user> userList = [select id, Name, isActive,RSM__c from User where isActive=true];
for(user u: userList){
    userMap.put(u.Name, u);     
}
system.debug('**userMap*'+userMap);

for(Sampling__c s :Trigger.new){


}   
}

So if I'm not going in the right direction, how do I populate my Map with ONLY the current users information? Thanks.

Update** So believe this should work, I updated it after looking at that link provided by Mark. Opinions?

User userObj=[Select u.UserType,u.UserRoleId,u.LastName, u.Id,u.RSM__c, u.FirstName,   u.ISR__c, UserRole.Name,UserRole.ParentRoleId From User u 
       where u.id=:userinfo.getUserId()];

Now after this I need to create a

List<User> lstParentUserObj= new List<User> 

is that the general jist?

1

You can get information about the context user using the UserInfo class. The method you may be most interested in is getUserId(), which you can then use to query for just the current user's information.

Documentation link: https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_userinfo.htm

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.