Search code examples
salesforceapex-code

userinfo.getuseremail() returns [email protected] in salesforce


I have created a package in salesforce that will make an http callout request with user's email id to get data for that email and add the data to some custom object. But when I tried using UserInfo.getUserEmail() as a request parameter but it makes a request with [email protected]. It does work when I run it on the dev account. I also tried using

1.String userName = UserInfo.getUserName();
2.User activeUser = [Select Email From User where Username = : userName limit 1];
3.String userEmail = activeUser.Email;

But line no 2 gave me an error saying List has no rows for assignment to SObject

This is my first salesforce package, so any help would be appreciated.


Solution

  • https://salesforce.stackexchange.com/questions/10413/userinfo-getuseremail-returns-noreplysalesforce-com-in-salesforce

    This was the problem. Daniel answered it well. For whoever is having same-similar problem, It happens because scheduled jobs are run on their server as 'phantom' processes. So we have to provide it with the installedid when using installhandler or creating schedules. It wont have any knowledge of user otherwise. Save the installedid somehow!