The 'Email Quote' button which is visible on the page layout on Quote records, is greyed out. I have added the 'Allow Email' permission to all of the Quote Status Values and this has not resolved the issue. Has anyone experienced a similar issue when working with Quotes?
[SalesForce] ‘Email Quote’ button issue
Related Solutions
So I finally got around to fixing the issue.
Just as @crop1645 said, if I simply INSERT
the Task
via a DML statement, I will be able to create a Task
with a Quote
's Id as the WhatId
.
So before, as a recap, I tried something like this:
Messaging.SingleEmailMessage newEmail = new Messaging.SingleEmailMessage();
newEmail.setToAddresses(new List<String> { emailAddress });
newEmail.setTargetObjectId(quoteBeingUsed.ContactId);
newEmail.setWhatId(quotesId);
newEmail.setTemplateId(TemplateId);
newEmail.setFileAttachments(new List<Messaging.EmailFileAttachment> { newAttachment });
Messaging.sendEmail(new List<Messaging.SingleEmailMessage> { newEmail });
This resulted in throwing the following exception:
System.EmailException: 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.: []
Now how I solved it was simple. However, I wanted to make sure I got the Task
information exactly like it was done by the Email Quote button. I changed the WhatId
for the SingleEmailMessage
to the related OpportunityId
and after the sendEmail
method I followed it with:
Task newQuoteEmailTask = new Task(Subject = 'Email: ' + newEmail.getSubject(),
OwnerId = UserInfo.getUserId(), WhatId = quotesId, WhoId = quoteBeingUsed.ContactId,
Status = 'Completed', ActivityDate = Date.today(), Priority = 'Normal',
Description = GenerateTaskComment(newEmail));
INSERT newQuoteEmailTask;
The Description
's method is the following:
private static String GenerateTaskComment(Messaging.SingleEmailMessage newEmail)
{
List<String> listOfFileNames = new List<String>();
for(Messaging.EmailFileAttachment singleAttachment : newEmail.getFileAttachments())
listOfFileNames.add(singleAttachment.getFileName());
String endOfDescription = '_____________________________________________________________________'
+ '\nPowered by salesforce.com\nhttp://www.salesforce.com/';
return 'Additional To: '+ String.join(newEmail.getToAddresses() != null ? newEmail.getToAddresses() : new List<String>(), ',')
+ '\nCC: ' + String.join(newEmail.getCcAddresses() != null ? newEmail.getCcAddresses() : new List<String>(), ',')
+ '\nBCC: ' + String.join(newEmail.getBccAddresses() != null ? newEmail.getBccAddresses() : new List<String>(), ',')
+ '\nAttachment'+ (listOfFileNames.size() > 1 ? 's' : '') + ': ' + String.join(listOfFileNames, ',')
+ '\n\nSubject: ' + newEmail.getSubject()
+ '\nBody:\n' + newEmail.getPlainTextBody()
+ '\n\n' + endOfDescription;
}
Ok, so yesterday I found out how to solve this.
I don't know if it is on purpose or not but I was impersonating non-admin users via my System Admin user, by going to Setup > Users > Login
If, on the other hand, I actually login as the user I want to test by going to the login screen and input my username and password, the whole process works fine. It's what we've been calling here on our team "the Salesforce Way"
Best Answer
To enable the 'Email Reservation' button, a PDF must be created (by clicking 'Create PDF' and saving the record. Once the new pdf record has been added to the 'Quote PDF's' related list, then the 'Email Reservation' button will become active.