I develop an email template which calls a Visualforce component with a custom controller (controller of the custom component).
I give an opportunity Id to my custom component and I would like load data (opportunity related lists) in the custom controller but it doesn't work.
I manage to forward the opportunity Id to the custom component which assign to a controller variable but in my controller, the variable is null..
This is the email template :
<messaging:emailTemplate subject="Quote Support" recipientType="Contact" relatedToType="Opportunity">
<messaging:htmlEmailBody >
<c:C01_SendEmailOpportunitySupport oppId="{!relatedTo.Id}" />
</messaging:htmlEmailBody>
The Visualforce component :
<apex:component controller="CC01_SendEmailOpportunitySupport" access="global">
<apex:attribute name="oppId" type="Id" description="Id of the opportunity" assignTo="{!opportunityId}"/>
...
</apex:component>
The custom controller :
public class CC01_SendEmailOpportunitySupport{
public Id opportunityId{get;set;}
public Opportunity theOpportunity{get; set;}
public String theDate{get; set;}
private DateTime theNow;
public OpportunityContactRole theOpportunityContactRole{get; set;}
public CC01_SendEmailOpportunitySupport(){
System.debug('*** parameters : ' + ApexPages.currentPage().getParameters().get('oppId'));
init();
}
public void init(){
System.debug('*** opportunityId : ' + opportunityId);
this.theOpportunity = this.getTheOpportunityById(this.opportunityId);
System.debug('*** theOpportunity : ' + theOpportunity );
this.theOpportunityContactRole= this.getThePrimaryContact(this.opportunityId);
System.debug('*** theOpportunityContactRole: ' + theOpportunityContactRole);
this.theNow = DateTime.now();
this.TheDate = this.theNow.day() + '/' + this.theNow.month() + '/' + this.theNow.year() + ' ' + this.theNow.hour() + ':' + this.theNow.minute();
}
}
I guess the custom controller is loaded before the variable is assigned.
Please, someone can say to me how I I can assign the variable opportunityId?
OpportunityId
is null.