You need to sign in to do that
Don't have an account?

Need Activity history for custom object if an email is send from Apex Email Class Setsaveasactivity(true) is not working
Hi All,
I want to track what are the Email Notifications has been sent from my custom Object .So i want to store whenever an email is send from Custom Object i need to store in Activity History .I used SetSaveAsActivity(true) is not working.Below is the code:
Set<String> emailSet = new Set<String>();
emailSet.addAll(emailAddress);
emailAddress = new List<String>();
emailAddress.addAll(emailSet);
emailAddressMapWithAccountId.put(acc.Id, emailAddress);
Set<String> emailSetBcc = new Set<String>();
emailSetBcc.addAll(emailAddressBcc);
emailAddressBcc = new List<String>();
emailAddressBcc.addAll(emailSetBcc);
emailAddressMapWithAccountIdBcc.put(acc.Id, emailAddressBcc);
mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(emailAddress);
mail.setBccAddresses(emailAddressBcc);
mail.setTemplateId(templates.get(0).Id);
if(contactIDSet.size() > 0){
mail.setTargetObjectId(contactIDSet.get(0));
mail.setWhatId(CustomobjectID);
}else{
if(con == null || con.Id == null) {
con=[SELECT Id FROM Contact Limit 1];
}
mail.setTargetObjectId(con.id);
mail.setSaveAsActivity(true);
mail.setTreatTargetObjectAsRecipient(false);
mail.setWhatId(CustomobjectID);
}
mailArray.add(mail);
I am not sure why SetSaveAsActivity is not working.I want to track all email under my custom object
Thanks in Advance
}
}
}
I want to track what are the Email Notifications has been sent from my custom Object .So i want to store whenever an email is send from Custom Object i need to store in Activity History .I used SetSaveAsActivity(true) is not working.Below is the code:
Set<String> emailSet = new Set<String>();
emailSet.addAll(emailAddress);
emailAddress = new List<String>();
emailAddress.addAll(emailSet);
emailAddressMapWithAccountId.put(acc.Id, emailAddress);
Set<String> emailSetBcc = new Set<String>();
emailSetBcc.addAll(emailAddressBcc);
emailAddressBcc = new List<String>();
emailAddressBcc.addAll(emailSetBcc);
emailAddressMapWithAccountIdBcc.put(acc.Id, emailAddressBcc);
mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(emailAddress);
mail.setBccAddresses(emailAddressBcc);
mail.setTemplateId(templates.get(0).Id);
if(contactIDSet.size() > 0){
mail.setTargetObjectId(contactIDSet.get(0));
mail.setWhatId(CustomobjectID);
}else{
if(con == null || con.Id == null) {
con=[SELECT Id FROM Contact Limit 1];
}
mail.setTargetObjectId(con.id);
mail.setSaveAsActivity(true);
mail.setTreatTargetObjectAsRecipient(false);
mail.setWhatId(CustomobjectID);
}
mailArray.add(mail);
I am not sure why SetSaveAsActivity is not working.I want to track all email under my custom object
Thanks in Advance
}
}
}
May I suggest you please check with below link from the stack exchange community exactly with a similar issue which will guide you in the right direction.
- https://salesforce.stackexchange.com/questions/81019/how-to-store-email-sent-from-apex-in-email-related-list
Please let us know if this helps.Kindly mark this post as solved if it's resolved so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.
Thanks,
Nagendra