You have a couple of issues here:
- Constructor
public SalesReportExtension(ApexPages.StandardController controller)
will never be called since you stated this is a custom controller (although I'm not so sure about this given your assertion that the VF page works fine). - When used in a VF Component, the constructor
public SalesReportExtension()
is called before the setter for the component'sassignTo="{!accountId}"
Hence, the SOQL select statement in the constructor public SalesReportExtension()
will not have a value for accountId
as the list accountIds
has only a single null element.
A handy reference is the VF Developer's Guide Order of Execution
Update
What triggers the email template to be rendered? Is it a workflow/approval process w/ email alert? if yes - then the record being triggered will implicitly be bound to relatedToType
.
I believe that sending an email from 'Send and Email' button on the Account's related lists will also implicitly bind the account to relatedToType
.
If using apex to send the email via some controller action or webservice, then the value of setWhatid(..)
does the binding.
When you test/preview in the Email template editor, you have to provide an Account in the popup dialog - this also does the binding.