Hello,
I'm not a developer but I'm trying to create custom print button for a Service Appointment list view. Unfortunately, the Service Appointment object doesn't have Printable View button. I found a code online, although, I'm getting an error:
Error: Cyclic page or component references '/apex/PrintServiceAppointmentList' are not allowed
If someone can kindly give me some tips on the code below, I would appreciate it. Thank you!
<apex:page>
<apex:page standardController="ServiceAppointment" recordSetVar="s" applyHtmlTag="false" showHeader="false" sidebar="false">
<apex:slds />
<apex:outputPanel rendered="{!NOT(ISNULL(paramPrint))}">
<script>
window.print(); // Triggers the print dialog
</script>
</apex:outputPanel>
<apex:outputPanel rendered="{!ISNULL(paramPrint)}">
<div class="slds-scope">
<h1 class="slds-text-heading_large">Service Appointments</h1>
<apex:repeat value="{!s}" var="sa">
<div class="slds-box slds-m-bottom_small">
<p><b>Appointmen tNumber:</b> {!sa.AppointmentNumber}</p>
<p><b>Account:</b> {!sa.AccountId}</p>
<p><b>Work Type:</b> {!sa.WorkTypeId}</p>
<p><b>Due Date:</b> {!sa.DueDate}</p>
<p><b>Description:</b> {!sa.Description}</p>
<p><b>Service Territory:</b> {!sa.ServiceTerritoryId}</p>
<p><b>Address:</b> {!sa.Address} {!sa.City}</p>
<p><b>Created By:</b> {!sa.CreatedById}</p>
</div>
</apex:repeat>
</div>
<!-- Button to view printable version -->
</apex:outputPanel>
<a href="/apex/PrintServiceAppointmentList?paramPrint=1" target="CarlosPMsUpcoming" class="slds-button slds-button_brand">Print This View</a>
</apex:page>
</apex:page>
@Salesforce Developers
#Salesforce Developers
hy @Michelle Johnson, The error happens because the page is calling itself using the same Visualforce URL, which creates a circular reference. You also have two apex:page tags, which is not allowed. Use only one apex:page, keep the standardController with recordSetVar, and remove the self-referencing link logic. For list view printing, you don’t need to reload the same page with a parameter; instead, render the list once and trigger window.print() directly, or use a separate Visualforce page purely for printing. That will avoid the cyclic reference and the error.