• Andreas Wolf 11
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
Hello guys,

I have 2 visualforce pages and 1 apex controller extension for both. On the first page I capture some information that is displayed on the second page (renderAs PDF). 

There is no problem showing a pdf preview with the following code:
public PageReference showPDF()
{
  PageReference test = Page.Sales_Offer_PDF;
  test.setRedirect(false);
  test.getParameters().put('Id', o.Id);
  test.getParameters().put('pdf','true');

  return test;
}
Though its still the first page in the url.

But if I want to save the second page as a pdf file, it completely ignores the second page and tries to get the content from the first page.
Following Code:
public void savePDF()
    {
        PageReference pdf = new PageReference('/apex/Sales_Offer_PDF?id='+o.Id+'&pdf=true');
        
        //PageReference pdf = Page.Sales_Offer_PDF;               Both ways dont work...
        //pdf.getParameters().put('Id', o.Id);
        //pdf.getParameters().put('pdf','true');

        Blob body;

        ContentVersion v = new ContentVersion();
        try {
            body = pdf.getContent();
        } catch (VisualforceException e) {
            body = Blob.valueOf('Some Text');
            System.debug('### Exception savePDF: '+e);
        }
        v.versionData = body;
        v.title = 'Offer ('+Date.today().format()+').pdf';
        v.pathOnClient ='/Offer ('+Date.today().format()+').pdf';
        v.ProtectedFile__c = false;        

        insert v;

        ID cdId = [SELECT Id, ContentDocumentId FROM ContentVersion WHERE ID =: v.Id].ContentDocumentId;

        ContentDocumentLink cdl = new ContentDocumentLink();
        cdl.ContentDocumentId = cdId;
        cdl.ShareType = 'V'; 
        cdl.LinkedEntityId = o.Id;
        cdl.Visibility = 'AllUsers'; 

        insert cdl;
    }
Btw. Im developing for Lightning Experience right now.
Can someone help me to save the second vf page as a pdf file. I need the same controller to keep the same view state..
Hello guys,

I have 2 visualforce pages and 1 apex controller extension for both. On the first page I capture some information that is displayed on the second page (renderAs PDF). 

There is no problem showing a pdf preview with the following code:
public PageReference showPDF()
{
  PageReference test = Page.Sales_Offer_PDF;
  test.setRedirect(false);
  test.getParameters().put('Id', o.Id);
  test.getParameters().put('pdf','true');

  return test;
}
Though its still the first page in the url.

But if I want to save the second page as a pdf file, it completely ignores the second page and tries to get the content from the first page.
Following Code:
public void savePDF()
    {
        PageReference pdf = new PageReference('/apex/Sales_Offer_PDF?id='+o.Id+'&pdf=true');
        
        //PageReference pdf = Page.Sales_Offer_PDF;               Both ways dont work...
        //pdf.getParameters().put('Id', o.Id);
        //pdf.getParameters().put('pdf','true');

        Blob body;

        ContentVersion v = new ContentVersion();
        try {
            body = pdf.getContent();
        } catch (VisualforceException e) {
            body = Blob.valueOf('Some Text');
            System.debug('### Exception savePDF: '+e);
        }
        v.versionData = body;
        v.title = 'Offer ('+Date.today().format()+').pdf';
        v.pathOnClient ='/Offer ('+Date.today().format()+').pdf';
        v.ProtectedFile__c = false;        

        insert v;

        ID cdId = [SELECT Id, ContentDocumentId FROM ContentVersion WHERE ID =: v.Id].ContentDocumentId;

        ContentDocumentLink cdl = new ContentDocumentLink();
        cdl.ContentDocumentId = cdId;
        cdl.ShareType = 'V'; 
        cdl.LinkedEntityId = o.Id;
        cdl.Visibility = 'AllUsers'; 

        insert cdl;
    }
Btw. Im developing for Lightning Experience right now.
Can someone help me to save the second vf page as a pdf file. I need the same controller to keep the same view state..
Hello,

I have an issue executing a report from Apex. I am getting the Fatal Error "Too many query rows: 50001" when I execute the method "Reports.ReportManager.runReport(reportId, reportMetadata, includeDetails)".

The report returns 13.000 contacts, but when I execute it from apex, it only return the first 2,000 contacts. To get all the records y execute the same report adding a new filter to exclude the contacts I already got adding "Reports.ReportFilter('Contact.Id', 'greaterThan', lastContactId);"

So if the report must return 13,000 records, I will have to run the report 8 times. Every time I run the report I consult the limits and I always get 3 in "Limits.getQueryRows()", but when is executing the report for 5th time I get this exception "System.LimitException: reports:Too many query rows: 50001"

My conclusion is that as the report has 13,000 records, it adds to the limit 13,000 records to the limit everytime the report is executed, so if the report has 50,000 record I will not be able to execute the report not eve once. But if I check the limit with "Limits.getQueryRows()" I will always get 3 records, and never 50,001.

Can anyone help me with this issue? Has anyone launched a report with more than 50,000 records from apex?

Thank you
Hello guys,

I have 2 visualforce pages and 1 apex controller extension for both. On the first page I capture some information that is displayed on the second page (renderAs PDF). 

There is no problem showing a pdf preview with the following code:
public PageReference showPDF()
{
  PageReference test = Page.Sales_Offer_PDF;
  test.setRedirect(false);
  test.getParameters().put('Id', o.Id);
  test.getParameters().put('pdf','true');

  return test;
}
Though its still the first page in the url.

But if I want to save the second page as a pdf file, it completely ignores the second page and tries to get the content from the first page.
Following Code:
public void savePDF()
    {
        PageReference pdf = new PageReference('/apex/Sales_Offer_PDF?id='+o.Id+'&pdf=true');
        
        //PageReference pdf = Page.Sales_Offer_PDF;               Both ways dont work...
        //pdf.getParameters().put('Id', o.Id);
        //pdf.getParameters().put('pdf','true');

        Blob body;

        ContentVersion v = new ContentVersion();
        try {
            body = pdf.getContent();
        } catch (VisualforceException e) {
            body = Blob.valueOf('Some Text');
            System.debug('### Exception savePDF: '+e);
        }
        v.versionData = body;
        v.title = 'Offer ('+Date.today().format()+').pdf';
        v.pathOnClient ='/Offer ('+Date.today().format()+').pdf';
        v.ProtectedFile__c = false;        

        insert v;

        ID cdId = [SELECT Id, ContentDocumentId FROM ContentVersion WHERE ID =: v.Id].ContentDocumentId;

        ContentDocumentLink cdl = new ContentDocumentLink();
        cdl.ContentDocumentId = cdId;
        cdl.ShareType = 'V'; 
        cdl.LinkedEntityId = o.Id;
        cdl.Visibility = 'AllUsers'; 

        insert cdl;
    }
Btw. Im developing for Lightning Experience right now.
Can someone help me to save the second vf page as a pdf file. I need the same controller to keep the same view state..