Ok so like I explained in a previous post were having an issue getting UserInfo inside a batchable that is scheduled to run every so often. The code below outlines how were are trying to access the user's
global class PostInstall implements InstallHandler {
global void onInstall(InstallContext context){
insert new MyApp__MySetting__c(
MyApp__userid__c = UserInfo.getUserId(),
MyApp__email__c = UserInfo.getUserEmail()
);
System.schedule('Initialize Test', '0 5 * * * ?', new EmailRecSchedable());
}
}
//this class should schedule the batchable to run
global class EmailRecSchedable implements Schedulable{
global void execute(SchedulableContext ctx){
BatchJob b = new BatchJob();
database.executebatch(b);
}
}
//this is a quick test we did to see if we can get the user's email
global class BatchContactMonkeyJob implements Database.Batchable<sObject>,Database.Stateful{
global BatchContactMonkeyJob(){
//send test email
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddress = new String[] {'[email protected]'};
mail.setToAddresses(toAddress);
mail.setReplyTo('[email protected]');
mail.setSenderDisplayName('CM Test');
MyApp__MySetting__c c = MyApp__MySetting__c.getInstance(UserInfo.getUserId());
mail.setSubject('Your Setting : ' + c.MyApp__email__c);
mail.setPlainTextBody('Your ID: ' + UserInfo.getUserId());
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
Once I install the app on another account, here is the response I get from salesforce. I should be seeing "Your Setting: " but as you can see from the screenshot, it says "[email protected]".
I really need this issue solved so, any suggestions or sample code is appreciated, thanks!