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
Subbu'sSubbu's 

need help to send Email with attachment in scheduled class

Hello Everyboby ,

 

I want to send an email with Messaging.sendEmail method with a pdf attachment ,but the problem is pageReference.getContent() method will not work in the scheduled class . So can anyone have the idea how to acheive this functionality in scheduled class.KIndly share me your ideas about this..

 

Thanx in Advance.

Vinita_SFDCVinita_SFDC

Hello,

 

As of now the getContent and getContentAsPDFPageReference methods can not be used in scheduled apex. A work around could be, implement your own webservice with the method that you want to call and calling that webservice from the @future method that is called by the scheduled APEX execute() method.

 

I would suggest you to vote following idea on idexchange portal:

 

https://success.salesforce.com/ideaView?id=08730000000ZlnBAAS

Subbu'sSubbu's

@Vinita

Hello ,

 

thx for your idea sharing .. I tried with the @future annotation ,still it is not working..

Vinita_SFDCVinita_SFDC

Hello,

 

With @future also getContent will not work, i am suggesting you to create a webservice and make use of getContent in that webservice. Now call that webservice with @future notation in your scheduled apex class.

Subbu'sSubbu's

@Vinita ,

 

Can you plz provide me sample code , how to use  the below statements  in webservice callout .

 

PageReference pg = page.Mypage;

Blob body = pg.getContent();

Vinita_SFDCVinita_SFDC

Hello,

 

Create a webservice that will be an apex class, like:

 

global class WebServiceClass {
    
    WebService static String sayHello(String s1){
       

PageReference pg = page.Mypage;

Blob body = pg.getContent();

 

return body;


    }
}

 

Now call this in your scheduled apex with @future(callout=ture)

Subbu'sSubbu's

@Vinita ,

 

Thx for your response .

 

I tried with your sample code ,but its not working.

 

The problem is we are receiving an email with attachement but in the attachment there is no content its just coming with minium size 1kb

 

we planned to acheive this using workflow ..