You need to sign in to do that
Don't have an account?
Id's and Email's
I am tring to create a class that will send an email to the boss of the owner of the custom time sheet object I created. This is what I have so far. I have tried settting the Ids and Emails by hard coding them in but that doesn't work. I would appreciate some tips.
Thanks for the help.
for(Time_Sheet__c sheet: TimeSheet){
if(sheet.Hours_Worked__c>40){
User you = [SELECT Email
FROM User
WHERE Id = :UserInfo.getUserId() LIMIT 1];
Messaging.Singleemailmessage mail =new Messaging.Singleemailmessage();
mail.setToAddresses(new String[] {you.Email});
mail.setSubject('Over time Hours');
mail.setPlainTextBody('Has hours of over time.');
Messaging.sendEmail(new Messaging.Singleemailmessage[] {mail});
}
}
for(Time_Sheet__c sheet: TimeSheet)
{
if(sheet.Hours_Worked__c>40)
{
User you = [SELECT Email FROM User WHERE Id = :UserInfo.getUserId() LIMIT 1];
Messaging.Singleemailmessage mail =new Messaging.Singleemailmessage();
mail.setToAddresses(new String[] {you.Email});
mail.setSubject('Over time Hours');
mail.setPlainTextBody('Has hours of over time.');
// It's Compulsory to set activity false
mail.setSaveAsActivity(false);
Messaging.sendEmail(new Messaging.Singleemailmessage[] {mail});
}
}
Please try with this one just set activity false. If it works please marked as solved