Activity Forums Salesforce® Discussions Salesforce Error : Callout from scheduled Apex not supported.

  • Salesforce Error : Callout from scheduled Apex not supported.

    Posted by Rahul on February 1, 2018 at 6:51 am

    Hi ,

    I am using apex code to send a report as an attachment and schedule it but in Scheduling i am getting this error
    "Scheduler: failed to execute scheduled job: jobId: 7012D00000IDppK, class: common.apex.async.AsyncApexJobObject, reason: Callout from scheduled Apex not supported."
    here is my code:
    global class Exporter implements System.Schedulable {
    global void execute(SchedulableContext sc) {
    ApexPages.PageReference report = new ApexPages.PageReference('/00O41000001kkjC?csv=1');
    Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment();
    attachment.setFileName('scheduledreport.csv');
    attachment.setBody(report.getContent());
    attachment.setContentType('text/csv');
    Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
    message.setFileAttachments(new Messaging.EmailFileAttachment[] { attachment } );
    message.setSubject(' Test Client list Report');
    message.setPlainTextBody('The report is attached.PFA');
    message.setToAddresses( new String[] { '[email protected]' } );
    Messaging.sendEmail( new Messaging.SingleEmailMessage[] { message } );

    }
    }
    Now i am not getting that where i am using Callout  services. How to resolve this?

    Thanks in advance!

    Rahul Kumar

    PRANAV replied 6 years, 9 months ago 2 Members · 1 Reply
  • 1 Reply
  • PRANAV

    Member
    March 27, 2018 at 1:59 pm

    Hi Rahul,

    If you want to do it in the schedule class you will need to do it in an @future method.

    If you want to do it within the batch that is ran by the schedule you will need to implement the callout interface.

    global class scheduledBatchable implements Schedulable, Database.AllowsCallouts

    To use a callout in batch Apex, specify Database.AllowsCallouts in the class definition.

    Hope this helps you.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos