I am sending a pdf in an email when the opportunity is created on updated which works fine. Now when the opportunity is created through batch so its throws the error future method can not call future method
because I use @future (callout= true)
in the handler class. when I remove @future
from the handler method so it also throws the error Getting content from within triggers is currently not supported.
I also tried to use if(System.IsBatch() == false && System.isFuture() == false)
then trigger can not executed.What is the best way to solve the problem like its works when I create a single opportunity without a batch? How to solve this while using batch?
if(trigger.isAfter && trigger.isInsert){
list<opportunity> oppList = [select id, name ,Email_Sending_Option__c,Language__c,Template__c,Email__c,
Email_Date__c,Email_Status__c from opportunity where id =: trigger.new ];
for(Opportunity opp:oppList) {
if(opp.Template__c != null && opp.Language__c != null){
if(opp.Email_Sending_Option__c == 'Send Now'){
opp.Email_Date__c = date.today();
opp.Email_Status__c = 'Email Sent';
updateOpp.add(opp);
if(System.IsBatch() == false && System.isFuture() == false){
PDFGenerationService.generatePDF1(opp.Template__c+'.pdf',opp.Email__c,opp.Id,opp.Template__c,opp.Language__c);
}
Apex classs
public class PDFGenerationService {
@future (callout=true)
public static void generatePDF(string filename, string email,ID OpportunityId,string pageName,string lang )
{
if(lang == 'English'){
EmailTemplate coverTemplate = EmailTemplateSelector.getEmailTemplate('Development And Peace');
Map<String, String> ncParams=new Map<String, String> {'{name}' => 'name'};
Messaging.EmailFileAttachment attach = EmailHelper.attachementBuilder(filename,OpportunityId,pageName,lang);
Messaging.SingleEmailMessage mail=EmailHelper.emailBuilder(email,coverTemplate.Subject,coverTemplate.HtmlValue,ncParams);
mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attach});
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}