function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
VSK98VSK98 

WHY Can't I Use SetTargetObjectId(UserId) and SetWhatId?

Hi,

I am calling template in mail method, SetTargetObjectId(UserId) and SetWhatId(Record id)

If i use SetWhatId(Record id) getting error Invalid_ID_Field

Please help me out

Advance Thanks
Siv
RatanRatan
Plz share your code.
VSK98VSK98
HI Ratan,

Here is my code



for(CAP__c w: H1bcap) {
          
          if(w.CAP_Business_Days_SM__c == 0 ) 
     {
           system.debug('size of the list' +H1bcap.size());
           system.debug('ID**********' +w.id);
                     
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
          
          
            mail.SetTemplateid(et.id);--------------------calling template id
            mail.setSaveAsActivity(false);
        
           mail.setTargetObjectId(w.SM_Name_r.id);-----------------User ID's
           
         mail.setWhatid(w.id);
          
           mail.setOrgWideEmailAddressId(owe.id);-------------------calling owa id 
           
           system.debug('IDDDDDDDDDDD*******' +owe.id);
  
            system.debug('IDDDDDDDDDDD*******' +et.id);
    
   
            mailList.add(mail);   
           } 
              
        } 
        if(mailList.size() >0)
      {  
        Messaging.sendEmail(mailList);   
      } 
Alessandro Passoni 9Alessandro Passoni 9
Hi VSK98,
did you ever get a reply to your question ?
found a workaround ?
thanks