You need to sign in to do that
Don't have an account?
ishchopra
Error on Job Run
Hello Everyone,
this is what i am getting when job runs:
First error: You have uncommitted work pending. Please commit or rollback before calling out
this is what i am getting when job runs:
First error: You have uncommitted work pending. Please commit or rollback before calling out
global class EmailReports implements Schedulable { global void execute(SchedulableContext sc) { CallSchedule.EmailReports(); } }
public class CallSchedule { @future(callout=true) public static void EmailReports() { String ReportID; String EvntName; List<string> reportids = new List<string>{'00OM0000000GzioMAC'}; // reports to send List<string> EventName = new List<string>{'EAGC+2016','LNGCAN+2017','CEE+2017','GASASIA+2016','Gastech+2017','GIS+2017'}; // Event Value to be passed runtime if (EventName.size() >0) { for (integer i=0 ; i < 5 ; i++) { ReportID = reportids[0]; EvntName = EventName[i]; ApexPages.PageReference report = new ApexPages.PageReference('/'+ ReportID + '?pv0=' + EvntName +'&csv=1'); Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment(); attachment.setFileName('report.csv'); attachment.setBody(Blob.valueof(report.getContent().toString())); //attachment.setBody(Blob.valueof(report1.getContent().toString())); attachment.setContentType('text/csv'); Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage(); message.setFileAttachments(new Messaging.EmailFileAttachment[] { attachment } ); message.setSubject('Report For' + EventName ); message.setPlainTextBody('The report is attached.'); message.setToAddresses( new String[] { 'skh@gmail.com' } ); Messaging.sendEmail( new Messaging.SingleEmailMessage[] { message } ); } } }
All Answers
It seems there are some pendig jobs.
Go to
Monitoring->Scheduled jobs
Delete them and save.
Let me know if it helps.
mark it as best answer if it helps.
Thanks.
We can not make a DML operation or send email after after you make callout.
So follow this order.
Callout
Callout
DML/Send Email
Please take a look at this.
https://help.salesforce.com/apex/HTViewSolution?id=000079772&language=en_US
Let me know if it helps.
mark it as best answer if it helps.
Thanks.
Appreciate your help on this, is there any way you can tell me where to place the Callout in my code above?
i am really new to apex therefore couldn't figure this out
A
That is what I am wondering at what line you are doing callout?
Please let me know.
Give it a try once.
mark it as best answer if it helps.
Thanks.
First error: Callout not allowed from this future method. Please enable callout by annotating the future method. eg: @Future(callout=true)
At what line you are doing callout?Please let me know