You need to sign in to do that
Don't have an account?

Need help rendering a page as a pdf and attaching it to potentially multiple records.
I'm trying to render an invoice for a user while at the same time attaching it to the applicable records in our database.
My current structure for the method is as follows:
body = page.getContent();
which is: Exception common.page.PageInterruptException, Cyclical server-side forwards detected
and I'm having trouble resolving it.
Any suggestions would be appreciated.
My current structure for the method is as follows:
public PageReference processSelection(){ List<ID> batchList = new List<ID>(); containerList = new List<ContractWrapper>(); updateList = new List<MG_Contract_Holder__c>(); MG_Contract_Holder__c updCon = new MG_Contract_Holder__c(); if(tContractList.size() > 0){ containerList.addall(tContractList); } if(twcContractList.size() > 0){ containerList.addall(twcContractList); } if(gapContractList.size() > 0){ containerList.addall(gapContractList); } if(mppContractList.size() > 0){ containerList.addall(mppContractList); } if(wsContractList.size() > 0){ containerList.addall(wsContractList); } if(upppcContractList.size() > 0){ containerList.addall(upppcContractList); } if(upppContractList.size() > 0){ containerList.addall(upppContractList); } if(uppContractList.size() > 0){ containerList.addall(uppContractList); } if(sealContractList.size() > 0){ containerList.addall(sealContractList); } if(pdrContractList.size() > 0){ containerList.addall(pdrContractList); } if(mpppcContractList.size() > 0){ containerList.addall(mpppcContractList); } if(mpppContractList.size() > 0){ containerList.addall(mpppContractList); } if(keyContractList.size() > 0){ containerList.addall(keyContractList); } if(keyplContractList.size() > 0){ containerList.addall(keyplContractList); } if(etchContractList.size() > 0){ containerList.addall(etchContractList); } Integer selectedCount2 = 0; for(contractWrapper sub : containerList){ if(!sub.selected){ continue; } if(sub.selected == true){ selectedCount2++; } if(selectedCount2 > 0){ subNum = sub.subNum; subVin = sub.subVin; system.debug('subNum: ' + subNum); system.debug('subVin: ' + subVin); updCon = [SELECT Contract_Status__c, Batch__c FROM MG_Contract_Holder__c WHERE Contract_Number__c =:subNum AND Vin_Number__c =:subVin]; batchList.add(updCon.Batch__c); system.debug('updCon'); updCon.Contract_Status__c = 'Submitted - Pending Payment'; updateList.add(updCon); } } if(selectedCount2 == 0){ ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'You must select at least one record to submit before proceeding.')); return null; } update updateList; Set<ID> myset = new Set<ID>(); List<ID> result = new List<ID>(); myset.addAll(batchList); result.addAll(myset); PageReference page = new PageReference('/apex/pages/CM_RemitReport'); page.setRedirect(true); for(integer i = 0; i < result.size(); i++){ Attachment attach = new Attachment(); Blob body; body = page.getContent(); attach.Body = body; attach.Name = 'RemitRegister.pdf'; attach.ParentId = result[i]; insert attach; } return page; }However, I hit an error on the line:
body = page.getContent();
which is: Exception common.page.PageInterruptException, Cyclical server-side forwards detected
and I'm having trouble resolving it.
Any suggestions would be appreciated.
http://www.salesforce.com/docs/developer/pages/Content/pages_email_sending_attachments.htm
The example renders a page as PDF and attaches it to an email...in your case you're attaching it to a record. Disclaimer: I've not examined your code very closely yet, so perhaps you've already used this as a template...