I'm getting this exception where trying to send email:
SendEmail failed. First exception on row 0; first error: INVALID_ID_FIELD, SaveAsActivity is not allowed with whatId that is not supported as a task whatId.: [whatId, 00301000002mirW]
I know it wil work if I will set the saveActivity to false, but I want it to be true.
WhatId in my case is ContactId, as can be seen in the script below.
Any idea what is the issue?
Contact con = [select Id,Email from Contact where Id = '00301000002mirW'];
Messaging.SingleEmailMessage mail = Messaging.renderStoredEmailTemplate('00X01000000LyOQ', null, con.Id);
mail.setTargetObjectId(con.Id);
mail.setToAddresses(new list<String>{con.Email});
mail.setReplyTo(con.Email);
mail.setBccSender(false);
mail.setUseSignature(false);
mail.saveAsActivity = true;
Messaging.sendEmail( new list<Messaging.SingleEmailMessage>{mail});