5

Suppose you have an app that schedules Batchables to run. If you wanted to access say the user ID and their email inside a batchable, so specifically in the execute(), how exactly can this be done?

What our app is doing is performing callouts, BUT we need the user information when sending the HTTP request to our api from salesforce.

Any help is appreciated, thanks.

1 Answer 1

3

For this, you can use:

UserInfo.getUserId();
UserInfo.getUserEmail();

See the documentation here for a full list of static methods that may be useful to you in this context.

Note, this will get information for the user that scheduled the Job in the first place which may/may not be what you need.

If you needed the same details for say a record owner, you would need to access that from the User object (using the OwnerId field as a lookup to User) within the execute() method itself.

3
  • exactly, thats the issue were having, the user email is always set to [email protected]. So how exactly can we get this OwnerId to perform the loopup? Commented Apr 12, 2013 at 20:15
  • @1337holiday, what are you saying here - you want the 'from' email address to be something other than [name] sent by [email protected]? What do you want it to be? (you might consider posting another question, your original post doesn't say that). Commented Apr 12, 2013 at 20:44
  • Ok I'm Going to do that, our team has been working on this issue for the past week and cant seem to get this solved, so if you can help us out that would be great, thanks! Commented Apr 12, 2013 at 20:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .