• oliver.clutterbuck1.397138123180078E12
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

Hello All

 

I got some problem on triggers .I am try to send a group mails by using triggers on custom object.

 I got this error message"INVALID_TYPE_FOR_OPERATION, Only Users, Contact or Lead allowed for targetObjectId ".

 

Can't we send group mails on coustom object by using a triggers.PLZ help me any one in this problem.

 

my code:

 

 

trigger RoomExpensesTrig on Rooom_mets__c (after insert) {


if(trigger.isInsert&&trigger.isAfter) {
Rooom_mets__c con1=[Select id from Rooom_mets__c limit 1];


List<Rooom_mets__c> emailID = [select Email_id__c from Rooom_mets__c];

String addresses;
if (emailID[0].Email_id__c!= null) {

addresses = emailID[0].Email_id__c;

for (Integer i = 1; i < emailID.size(); i++){

if (emailID[i].Email_id__c != null)
{
addresses += ':' + emailID[i].Email_id__c;
}
}
}

String[] toAddresses = addresses.split(':', 0);


EmailTemplate et=[Select id from EmailTemplate where name=:'VFTmpToEmail'];

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

mail.setToAddresses( toAddresses );
mail.setTargetObjectId(con1.Id);
mail.setSenderDisplayName('LAKSHMI3VENI');
mail.setTemplateId(et.id);

Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail}); 


}
}

  • August 31, 2012
  • Like
  • 0