0

I am using a recommended solution to send case email when there is no contact (create/rollback) email then send the message that was created. However its not attaching to the case. When there is a contact associated to the case it does save the email on the case but I cant see why it wouldnt when there is no contact. I am setting the WhatId and also saveasactivity methods but no dice

            Messaging.SingleEmailMessage msg = new Messaging.SingleEmailMessage();
            msg.setTemplateId(tempId);
            msg.setWhatId(Cas.id);
            msg.setTargetObjectId(cnt.id);
            msg.setToAddresses(new List<String>{'[email protected]'});
            msg.setSaveAsActivity(True);
            msgList.add(msg);

            Savepoint sp = Database.setSavepoint();
            Messaging.sendEmail(msgList);
            Database.rollback(sp); 

            List<Messaging.SingleEmailMessage> msgListToBeSend = new
            List<Messaging.SingleEmailMessage>();
            for (Messaging.SingleEmailMessage email : msgList)
                 {
                      Messaging.SingleEmailMessage emailToSend = new Messaging.SingleEmailMessage();
                      emailToSend.setToAddresses(new String[]{Cas.SuppliedEmail});
                      emailToSend.setPlainTextBody(email.getPlainTextBody());
                      emailToSend.setHTMLBody(email.getHTMLBody());
                      emailToSend.setSubject(email.getSubject());
                      emailToSend.setSaveAsActivity(True);
                      emailToSend.setWhatId(Cas.id);
                      msgListToBeSend.add(emailToSend);
                 }

         Messaging.sendEmail(msgListToBeSend);

1 Answer 1

0

seems that without the TargetObjectId you wont be able to store this as an activity. for our B2C cases we dont have contact or account association on case so we cant do anything other than creat a dummy contact

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .