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
CotralLabWebDevCotralLabWebDev 

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 CotralLabWebDev
Hanimi ReddyHanimi Reddy
Hope this will solve your issue..

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

All Answers

CotralLabWebDevCotralLabWebDev
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
CotralLabWebDevCotralLabWebDev
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.