• Idealist Consulting 26
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
I have an apex extension for a visualforce page that sends emails using the SignleEmailMessaging method. It sends email using an email template with merge fields from a custom object called ParticipantEmail. However, I am getting an error on the WhatId method call.

here is that part of the code:
       //the class WrapTemp has two attributes, one of type ParticipantEmail__c named tempRec and the second one is a string named type_member
        for (WrapTemp wCM : pEmails){
            Messaging.SingleEmailMessage mess = new Messaging.SingleEmailMessage();
            List<String> bccAddys = new List<String>();
            bccAddys.add(UserInfo.getUserId());
            mess.setBccAddresses(bccAddys);
            system.debug('wCM.tempRec.ContactId = ' + wCM.tempRec.ContactId__c);
            system.debug('wCM.tempRec.Id = '+wCM.tempRec.Id);
            //set the contact to be emailed
            mess.setTargetObjectId(wCM.tempRec.ContactId__c);
            system.debug('wCM.tempRec.Id = '+wCM.tempRec.Id);
            id theRecId = wCM.tempRec.Id;
            system.debug('theRecId = '+ theRecId);            
            mess.setWhatId(theRecId);
            if (wCM.type_member == 'Participant') 
                mess.setTemplateId(temp.Id);
            else 
                mess.setTemplateId(volTemp.Id);                 
            messages.add(mess);            
        }
        messaging.sendEmail(messages);

Here is what I get from the debugger:
User-added image
It says the id is a284B0000007BOiQAM

but then the error I get says this 


System.EmailException: SendEmail failed. First exception on row 0; first error: INVALID_ID_FIELD, Invalid entity type for whatId.: [whatId, a284B0000007BPf]
Error is in expression '{!SendTheEmails}' in component <apex:commandButton> in page cmsendemailsvf: Class.CMSendEmails.SendTheEmails: line 129, column 1


Does anyone see what my problem is here?  I have no idea.