+ Start a Discussion
fsonnetfsonnet 

setwhatid in quote for apex email

Hi everyone,
I'm developping an automatic email in an apex class.

I'm trying to link my email to a quote with the methode setWhatId, but it don't work with quote...

Can you help me or give me another solution plese ?

This is my code:
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
List<String> sendTo = new List<String>();
sendTo.add('XXXX@XXXX.XXX');
mail.setToAddresses(sendTo);
mail.setTargetObjectId(quote.ContactId);
mail.setReplyTo('XXXX@XXXX.XXX');
mail.setTemplateId('XXXXXXXXXXXX');
mail.setwhatid(quote.Id);
mail.setSaveAsActivity(true);
Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});

Thanks.
Best Answer chosen by fsonnet
Hanimi ReddyHanimi Reddy
Hope this will solve your issue..

http://salesforce.stackexchange.com/questions/68955/singleemailmessage-setwhatid-with-quote-id

All Answers

fsonnetfsonnet
This is my error :

SendEmail failed. First exception on row 0; first error: INVALID_ID_FIELD, Only accounts, assets, campaigns, cases, contracts, opportunities, orders, products, solutions and custom objects are allowed as whatId.: [whatId, MYQUOTEID]
Hanimi ReddyHanimi Reddy
Hope this will solve your issue..

http://salesforce.stackexchange.com/questions/68955/singleemailmessage-setwhatid-with-quote-id
This was selected as the best answer
fsonnetfsonnet
Yes it works ! Thanks a lot :)
Mitesh SuraMitesh Sura
Hi fsonnet,

Can you please help? When you say "it works" , are you able to use email template along with Quote merge fields as well? There are 2 issues with WhatId
- Associating email to quote
- Using email template with Quote merge fields

Are you able to solve 2nd issue as well? Thank you for your time.