• kevin_car
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies

 

Hi,
Well, right on the heels of "Man"ish's question, here I am with an @future question...

I read that it's possible to schedule a report to run using @future with an HTTP callout, but I'm having absolutely no luck. Hoping someone has Ideas. All of the below seems to work, but I neve get the results emailed to me.

The email address and the report ID are stored in a Custom settings group down in the Exporter class...

 

The anonymous Apex:

 String s = '1 04 19 24 1 ?'; 
 Exporter  abc = new Exporter ();
 system.schedule('Report Job', s, abc);

 

The Schedulable class:

global class ReportExporter implements System.Schedulable {
    global void execute(SchedulableContext sc) {
    getmailReportOutput gem = new getmailReportOutput();
    gem.runReport();
    }
}

 

The class that does te HTTP callout to the  VF page that calls the class that generates and emails the report:

public class getmailReportOutput{
    
    public getmailReportOutput() {
        }
    
    public void runReport() {
        makeReportRequest();
        }
        
@future (callout=true)      
    public static void makeReportRequest()  {   
        ReportName__c mc = ReportName__c.getValues('ReportName');
        String strEmailAddr =  mc.RptEmail__c;
        URL xHost = System.URL.getSalesforceBaseUrl();
        String strHost =xHost.getHost();
        String requestUrl =  'https://' + strHost + '/apex/TestSendReport';
        HttpRequest req = new HttpRequest();
        req.setEndpoint(requestUrl);
        req.setMethod('GET');
        req.setHeader('Cookie','sid=' + UserInfo.getSessionId());
        String output = new Http().send(req).getBody();
        }
    }
    

 

The VF page that calls the class that generates the report and emails the CSV file:

<apex:page controller="Exporter" action="{!executeRpt}">
  <!-- Begin Default Content REMOVE THIS -->  
  <!-- End Default Content REMOVE THIS -->
</apex:page>

 

...And lastly, the class that does the actual work of generating the results and emailing them off:

 

public class Exporter {
    public static Boolean isTest;
    public static String strEmailAddr;
    
    void Exporter() {
        isTest = false;
        }
    
    public void execute    () {
        getmailReportOutput gem = new getmailReportOutput();
        gem.runReport();
        }
        
    public void setSendRpt(String locEmailAddr) {  
        isTest = false;
        strEmailAddr =  locEmailAddr;
        }
  
   public void setTest() {
        isTest = true;
        }

    public PageReference runThisPage() {
        ApexPages.PageReference report = new ApexPages.PageReference('/apex/TestSendReport');
        return report.setRedirect(false);
        }
        
             
    public void executeRpt() {
        System.debug('CALLING REPORT EXPORTER...');        
        ReportName__c mc = ReportName__c.getValues('ReportName');
        strEmailAddr =  mc.RptEmail__c;
        
        System.debug('ReportName:' +  mc.RptName__c);
        System.debug('EmailAddr:' + mc.RptEmail__c);
        integer a = 1;
        ApexPages.PageReference report = new ApexPages.PageReference( '/' + mc.RptName__c + '?csv=1');
         
        Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment();
        attachment.setFileName('report.csv');
        attachment.setBody(report.getContent());
        attachment.setContentType('text/csv');
        Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
        message.setFileAttachments(new Messaging.EmailFileAttachment[] { attachment } );
        message.setSubject('Report');
        message.setPlainTextBody('The report is attached.');
        message.setToAddresses( new String[] { strEmailAddr } );
        Messaging.sendEmail( new Messaging.SingleEmailMessage[] { message } );        
    }
 
}

 

If I just call the page, it all works great- all I ned to do is figure out how to schedule the page... but no luck.

 

Any help is appreciated.

 

Thanks

 

 

 

 

 

 

 

 

 

 

Hi -

 

Is it possible to create a report that combines Leads, with call activities and converted opportinity information all on one report?

 

I tried building a combined report based on lead and activity, but I am required to have summary information - and obviously we can't insert rollup fields on leads.

 

Has anyone done this before?

 


Thanks in Advance,

 

 

Hi,
Well, right on the heels of "Man"ish's question, here I am with an @future question...

I read that it's possible to schedule a report to run using @future with an HTTP callout, but I'm having absolutely no luck. Hoping someone has Ideas. All of the below seems to work, but I neve get the results emailed to me.

The email address and the report ID are stored in a Custom settings group down in the Exporter class...

 

The anonymous Apex:

 String s = '1 04 19 24 1 ?'; 
 Exporter  abc = new Exporter ();
 system.schedule('Report Job', s, abc);

 

The Schedulable class:

global class ReportExporter implements System.Schedulable {
    global void execute(SchedulableContext sc) {
    getmailReportOutput gem = new getmailReportOutput();
    gem.runReport();
    }
}

 

The class that does te HTTP callout to the  VF page that calls the class that generates and emails the report:

public class getmailReportOutput{
    
    public getmailReportOutput() {
        }
    
    public void runReport() {
        makeReportRequest();
        }
        
@future (callout=true)      
    public static void makeReportRequest()  {   
        ReportName__c mc = ReportName__c.getValues('ReportName');
        String strEmailAddr =  mc.RptEmail__c;
        URL xHost = System.URL.getSalesforceBaseUrl();
        String strHost =xHost.getHost();
        String requestUrl =  'https://' + strHost + '/apex/TestSendReport';
        HttpRequest req = new HttpRequest();
        req.setEndpoint(requestUrl);
        req.setMethod('GET');
        req.setHeader('Cookie','sid=' + UserInfo.getSessionId());
        String output = new Http().send(req).getBody();
        }
    }
    

 

The VF page that calls the class that generates the report and emails the CSV file:

<apex:page controller="Exporter" action="{!executeRpt}">
  <!-- Begin Default Content REMOVE THIS -->  
  <!-- End Default Content REMOVE THIS -->
</apex:page>

 

...And lastly, the class that does the actual work of generating the results and emailing them off:

 

public class Exporter {
    public static Boolean isTest;
    public static String strEmailAddr;
    
    void Exporter() {
        isTest = false;
        }
    
    public void execute    () {
        getmailReportOutput gem = new getmailReportOutput();
        gem.runReport();
        }
        
    public void setSendRpt(String locEmailAddr) {  
        isTest = false;
        strEmailAddr =  locEmailAddr;
        }
  
   public void setTest() {
        isTest = true;
        }

    public PageReference runThisPage() {
        ApexPages.PageReference report = new ApexPages.PageReference('/apex/TestSendReport');
        return report.setRedirect(false);
        }
        
             
    public void executeRpt() {
        System.debug('CALLING REPORT EXPORTER...');        
        ReportName__c mc = ReportName__c.getValues('ReportName');
        strEmailAddr =  mc.RptEmail__c;
        
        System.debug('ReportName:' +  mc.RptName__c);
        System.debug('EmailAddr:' + mc.RptEmail__c);
        integer a = 1;
        ApexPages.PageReference report = new ApexPages.PageReference( '/' + mc.RptName__c + '?csv=1');
         
        Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment();
        attachment.setFileName('report.csv');
        attachment.setBody(report.getContent());
        attachment.setContentType('text/csv');
        Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
        message.setFileAttachments(new Messaging.EmailFileAttachment[] { attachment } );
        message.setSubject('Report');
        message.setPlainTextBody('The report is attached.');
        message.setToAddresses( new String[] { strEmailAddr } );
        Messaging.sendEmail( new Messaging.SingleEmailMessage[] { message } );        
    }
 
}

 

If I just call the page, it all works great- all I ned to do is figure out how to schedule the page... but no luck.

 

Any help is appreciated.

 

Thanks

 

 

 

 

 

 

 

 

 

 

Hey All,

I am having trouble with the below class and am hoping to get some help.  I have a Junction Object that is connecting two custom Objects, Order__c and Product_Bundle__c and I am creating a Visualforce Page that will allow the User to create the Junction Objects by adding Quantity to the records and saving the page.  The class is designed to:

1.  Query the Product_Bundle__c Custom Object for available Product Bundles and assocate them behind the scenes with the current Order__c

2.  Display them on a VF page with the inputField Quantity__c exposed

3.  If the User enters a quantity and clicks "Save", the system will create those Junction  Objects associating the Product Bundles to the Order

 

I cannot seem to get my PageBlockTable to use the list in my Controller:

ErrorError: Unknown property 'Order_Item_Junction__cStandardController.lstoitem'

 

Any help on the below code would be great!

 

Class

public class oitemController
{
    public List<Product_Bundle__c> lstbundle = new List<Product_Bundle__c>();
    public List<Order_Item_Junction__c> lstoitem = new List<Order_Item_Junction__c>();
    public string orderid;
    public boolean proceed {get;set;}
    
    public boolean setproceed()
    {
        return true;
    }
    
    public oitemController(ApexPages.StandardController controller)
    {
        string flag = '';
        //Order ID
        orderid = ApexPages.currentPage().getparameters().get('oid');
        //Record Type
        string orecordtype = ApexPages.currentPage().getparameters().get('rectype');
        //Use this variable to test the code coverage of try-catch block within constructor and set to 'true'
        String calledFromTestClass = ApexPages.currentPage().getparameters().get('calledFromTestClass');
        
            if(orecordtype == 'New Order')
            {            
                flag = 'new';
                //Fetch all Product Bundles where Order_Availability__c = New Order
                lstbundle = [Select Order_Availability__c, Name, Id From Product_Bundle__c where Order_Availability__c =:'New Order' and Completed__c =: TRUE order by Name];
            }
            else if(orecordtype == 'Return Order')
            {
                flag = 'return';
                //Fetch all Product Bundles where Order_Availability__c = Return Oder
                lstbundle = [Select Order_Availability__c, Name, Id From Product_Bundle__c where Order_Availability__c =:'Return Order' and Completed__c =: TRUE order by Name];
            }
        
        List<Order_Item_Junction__c> lstoitem = new List<Order_Item_Junction__c>();
        
        if(calledFromTestClass == 'true') {
            lstoitem = null;
        }
        
        try{
        for(integer i=0;i<lstbundle.size();i++)
        {
            Order_Item_Junction__c oitem = new Order_Item_Junction__c();
            oitem.Product_Bundle__c = lstbundle[i].Id;
            oitem.Order__c = orderid;
            lstoitem.add(oitem);
            
        }
        }catch(Exception ex){
            // Adding exeption message onto the page
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Error:'+ ex.getMessage()));
            System.debug(ex.getMessage());
        }
    }   
}

 Page

<apex:page id="orderpage1" standardController="Order_Item_Junction__c" extensions="oitemController" sidebar="false" showheader="false" >
<script type="text/javascript">
function refreshparent()
{
    window.opener.location.reload();
    window.close();
}
</script>
    <apex:form id="form1">
        <apex:pageBlock title="Add Order Items" id="order">
            <apex:pageBlockButtons location="top">
                <apex:commandButton status="processingimg" value="Save" action="{!save}" rerender="order" oncomplete="refreshparent()" />
                <apex:commandButton onclick="javascript&colon;window.close();" value="Cancel" />
                <apex:actionstatus id="processingimg" >
                    <apex:facet name="start">
                        <apex:image id="theImage" value="{!$Resource.ProcessingImage}" />
                    </apex:facet>
                </apex:actionstatus>
            </apex:pageBlockButtons>
                <apex:pageBlockSection id="pbsbundle" title="Available Product Bundles" rendered="true" columns="1">
                    <apex:pageBlockTable id="pbtbundles" value="{!lstoitem}" var="l" width="100%">
                        <apex:column headervalue="Product Bundle Name" value="{!l.Product_Bundle__c}" width="80%"/>
                    </apex:pageBlockTable>
                </apex:pageBlockSection>
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton status="processingimg" value="Save" action="{!save}" rerender="order" oncomplete="refreshparent()"/>
                <apex:commandButton onclick="javascript&colon;window.close();" value="Cancel" />
                <apex:actionstatus id="processingimg1" >
                    <apex:facet name="start">
                        <apex:image id="theImage1" value="{!$Resource.ProcessingImage}" />
                    </apex:facet>
                </apex:actionstatus>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

  • January 10, 2012
  • Like
  • 0