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
kathybbkathybb 

What does Cyclical server-side forwards detected mean?

I'm writing a method to create a PDF Purchase Order and add it as an attachment to the PO record (custom object).

Here's the relavent apex code:

 

 public PageReference ViewPDF()
    {      
        system.debug('m_currentId = '+m_currentId);
        List<SFDC_Purchase_Requisition__c> m_reqResultList = new List<SFDC_Purchase_Requisition__c>();
        PageReference retPDF = new PageReference('/apex/PDFPO?id='+m_currentId);
        system.debug('m_myPO = '+ m_myPO);
        string PDFqueryPO = 'select Name, CreatedBy.name, Ship_To_Location__c,Expedite__c,PO_Date__c, Owner.id, Total_Price__c, PO_Notes__c from SFDC_Purchase_Order__c where Id = :m_currentId Limit 1';
        
        SFDC_Purchase_Order__c PDFPO = new SFDC_Purchase_Order__c();
        PDFPO =(SFDC_Purchase_Order__c)database.query(PDFqueryPO);
        string PDFReqResultListquery = m_RequestQueryByPOid;
        m_reqResultList= database.query(PDFReqResultListquery);
        m_displayResultList = new List<SFDC_Purchase_Requisition__c>();
        For(SFDC_Purchase_Requisition__c x : m_reqResultList)
        {
            if(x != null){
            x = (SFDC_Purchase_Requisition__c)x;
            m_displayResultList.add(x);
            }
           m_PDFPage = attach();
        }
        return m_PDFPage;
    }
      
    public PageReference attach() 
    {
         system.debug('m_currentId = '+m_currentId);
        Attachment myAttach = new Attachment();
         system.debug('m_currentId = '+m_currentId);
        myAttach.ParentId = m_currentId;    //Id of the object to which the page is attached
        if(m_myPO != null)
        {
            string myFileName = (m_myPO.name + ' - '+ date.TODAY() + '.PDF');
            myAttach.name = myFileName;
            PageReference myPdf = new PageReference('/apex/PDFPO?id=' + m_currentID);
            
            
            myAttach.body = myPdf.getContentAsPdf();
            try 
            {
                database.SaveResult sra = database.insert(myAttach);
                if(sra.issuccess() == true)
                {
                m_currentAttachId = sra.getID();
                }
                else
                {
                    // Operation failed, so get all errors                
                    for(Database.Error err : sra.getErrors()) 
                    {
                        System.debug('The following error has occurred.');                    
                        System.debug(err.getStatusCode() + ': ' + err.getMessage());
                        System.debug('Attachment fields that affected this error: ' + err.getFields());
                    } 
                } 
            } catch(Exception e){
                system.debug('Creation of PDF Failed');
                system.debug('Message was: '+ e);
        }
    }
        return m_PDFPage;
    }

 And here's the visualforce page 

 

<apex:page standardController="SFDC_Purchase_Order__c" extensions="AttachPRTOPOExtension" name="PDFPO" renderAs="PDF" action="{!ViewPDF}">
	<apex:outputPanel id="POInfo" layout="Block" style="font:Arial font-size: 9pt">
		<apex:outputField value="{!SFDC_Purchase_Order__c.Name}"/>
		<br />
		<apex:outputField value="{!SFDC_Purchase_Order__c.PO_Date__c}"/>
		<apex:outputField value="{!SFDC_Purchase_Order__c.Status__c}"/>
		<br />
		<apex:outputField value="{!SFDC_Purchase_Order__c.Ship_To_Location__c}"/>
		<apex:outputField value="{!SFDC_Purchase_Order__c.Expedite__c}"/>
		<br />
        <br />
	</apex:outputPanel>     
	<apex:DataTable value="{!m_displayResultList}" var="r" border="1px" cellpadding="1px" cellspacing="2px">
		<apex:column width="10%" headerValue="Request" value="{!r.name}" />
		<apex:column width="10%" headerValue="Requested By" value="{!r.Createdby.name}"/>
		<apex:column width="10%" headerValue="Request Date" value="{!r.CreatedDate}"/>
		<apex:column width="10%" headerValue="Quantity" value="{!r.Quantity__c}" />
		<apex:column width="10%" headerValue="Item Requested" value="{!r.Item_Requested__r.Name}" />
		<apex:column width="10%" headerValue="Price" value="{!r.Item_Requested__r.Price_per_unit__c}" />
		<apex:column width="10%" headerValue="Extended Price" value="{!r.Extended_Price__c}" />
		<apex:column width="10%" headerValue="Receive-by Date" value="{!r.Receive_by_Date__c}" />
	</apex:DataTable>
	<apex:relatedList list="Purchase_Requisitions__r" Title="Requisitions connected with this PO"/>
     <apex:relatedList list="NotesandAttachments" Title="Notes and Attched PDF PO"/>
</apex:page>

 I'm compiling it as version 25, to avoid the bug earlier reported to Salesforce.  

 

Can someone explain what I'm doing wrong in my controller extension?  This is the first time I've tried to generate a PDF file and attach it to a record, so any insight would be very appreciated.

Thanks in advance.

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

That sounds like your page action method (ViewPDF) is returning a pagereference that points to the page you are currently on.

 

All Answers

bob_buzzardbob_buzzard

That sounds like your page action method (ViewPDF) is returning a pagereference that points to the page you are currently on.

 

This was selected as the best answer
kathybbkathybb

That was it.

I really appreciate your help!

kathybb

Sayandip ghoshSayandip ghosh
Hi, 

I have a requirement almost like same. I have VF page in the page i have a command button. when i click on the button the page content must be save as a pdf attachment to the Quote Object.

For that i have use below method

ApexPages.currentPage().getContent()  which is throwing error 
common.apex.runtime.impl.ExecutionException: Exception common.page.PageInterruptException, Cyclical server-side forwards detected

Below is my method:
public PageReference attachFileToQuote(){
        

    	Id parentId = this.quoteId;
    	String pdfName = 'Oracle Response ' + System.now() + '.pdf';
    	PageReference pageRef = new PageReference('/apex/UpgradeAdvisor?Id='+parentId);//ApexPages.currentPage();

        system.debug('pageRef : '+pageRef);
        Blob pageRefPdf;
        try{
            pageRefPdf = pageRefPdf = pageRef.getContent();
            system.debug('pageRefPdf : '+pageRefPdf);
            //pageRefPdf = Blob.valueOf(pageRef);
            

            ContentVersion conVer = new ContentVersion();
            conVer.External_Key__c = pdfName ;
            conVer.PathOnClient = pdfName;
            conVer.Title = pdfName;
            conVer.VersionData = pageRefPdf;
            insert conVer;

            system.debug('conVer: '+conVer);
            ContentVersion conv = [select id,ContentDocumentId from ContentVersion where id =: conVer.id ];
            system.debug('conv: '+conv);

            ContentDocumentLink conDocLink = new ContentDocumentLink();
            conDocLink.ContentDocumentId = conv.ContentDocumentId;
            conDocLink.LinkedEntityId = parentId;
            conDocLink.ShareType = 'V';
            insert conDocLink;
        }catch (Exception e) {
            pageRefPdf = Blob.valueOf('Error has occurred: '+e.getMessage());
            system.debug('in catch : '+e.getMessage());
        }
        PageReference nextPage = new PageReference('/' + parentId);
        return null;

 
}


 
Ravinder pratap SinghRavinder pratap Singh
Try Creating separate classes for both the vf pages, this helped me to overcome this problem.