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
Andy Kallio 7Andy Kallio 7 

Maximum call stack size exceeded force:refreshview

Hello friends. I'm a junior developer and running into the following error: 
Uncaught Action failed: c:pdfDI_SelectTemplate2$controller$refresh [Maximum call stack size exceeded]
My project is to generate visualforce pdfs with these lightning components. So the main body of the component you see below is a picklist where the user will select the vfpage to be rendered as pdf. And the child component is just an inframe that will then display the selected pdf. All of that is working nicely but I noticed that if the record is edited then the pdf is not refreshed. So, I had a go with force:refreshview which gives me the error. I also found a suggestion for location.reload() but that refreshes the entire page. Hoping someone out there can help me solve this error.  Thanks!!
Here is my code:
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,force:hasRecordId,force:hasSObjectName,lightning:isUrlAddressable" 
                access="global" 
                controller="pdfDI_SelectTemplate2_Controller">
    
    <aura:attribute name="selectedTemplate" type="String"/>
    <aura:attribute name="templateOptions" type="List"/>
    <aura:attribute name="simpleRecord" type="Object"/> 
    <aura:attribute name="vfPage" type="String"/>
    <aura:handler event="force:refreshView" action="{!c.refresh}" />
 
    
    <force:recordData aura:id="recordLoader"
        recordId="{!v.recordId}"
        fields="Name, RecordTypeId"
        targetFields="{!v.simpleRecord}"
        recordUpdated="{!c.handleRecordUpdated}"  
    />
    
   
    <lightning:layout multipleRows="false">
        <lightning:layoutItem size="6">
        	<div class="row">
                <aura:if isTrue="{!v.templateOptions != null}">
                    <ui:inputSelect class="single" aura:id="InputSelectSingle" change="{!c.onSingleSelectChange}">
                        <option value="">...Select a Template...</option>
                        <aura:iteration items="{!v.templateOptions}" var="t_opt" indexVar="key">
                            <ui:inputSelectOption text="{!t_opt.value}" label="{!t_opt.key}"/>
                        </aura:iteration>
                    </ui:inputSelect>
                </aura:if>    
    		</div>
        </lightning:layoutItem>
    	<lightning:layoutItem size="6">
        <div class="slds-p-left_large">
    	 	<lightning:button label="Save PDF" title="Save PDF" onclick="{! c.savePDF }"/>
    	</div>
        </lightning:layoutItem>  
    </lightning:layout>
	<div class="slds-p-top_large">
        <p>PDF Preview:</p>
    	<c:pdfDI_DisplayTemplate selectedTemplate="{!v.selectedTemplate}" recordId2="{!v.recordId}" vfPage="{!v.vfPage}"/>
    </div>  
</aura:component>
 
({ 
    
    refresh : function(component, event, helper) {
		$A.get('e.force:refreshView').fire();
		//location.reload();
	},
    
    handleRecordUpdated: function(cmp, event, helper) {
        
        var eventParams = event.getParams();
        if(eventParams.changeType === "LOADED") {
        
            var actionVF = cmp.get("c.getVFPage");
            actionVF.setParams({
                sObjectName : cmp.get("v.sObjectName"),
                recordTypeId : cmp.get("v.simpleRecord.RecordTypeId")
            });
            actionVF.setCallback(this, function(response) {
           		
                var stateVF = response.getState();
            	if(stateVF == "SUCCESS") {
                	var vfpage;
                    vfpage = response.getReturnValue();
                    cmp.set("v.vfPage", vfpage);
            	}
            });
           // Send action off to be executed
           $A.enqueueAction(actionVF);
            
            //get template options
            var actionComp = cmp.get("c.getTemplateOptions");
            actionComp.setParams({ 
                sObjectName : cmp.get("v.sObjectName"),
                recordTypeId : cmp.get("v.simpleRecord.RecordTypeId")
            });
            // Add callback behavior for when response is received
            actionComp.setCallback(this, function(response) {
                var state = response.getState();
                if (state === "SUCCESS") {
                    var custs = [];
                    var conts = response.getReturnValue();
                    for(var key in conts) {
                        custs.push({value:conts[key], key:key});
                    }
                    cmp.set("v.templateOptions",custs);
                }
                else {
                    console.log("Failed with state: " + state);
                }
            });
            // Send action off to be executed
            $A.enqueueAction(actionComp);
            
        } else if(eventParams.changeType === "CHANGED") {
            
        } else if(eventParams.changeType === "REMOVED") {
            // record is deleted
        } else if(eventParams.changeType === "ERROR") {
            var errors = response.getError();
            console.log('errors '+errors);
        }
    },
    
    onSingleSelectChange: function(cmp) {
        var selectCmp = cmp.find("InputSelectSingle");
        cmp.set("v.selectedTemplate", selectCmp.get("v.value"));
	},
    
    savePDF : function(cmp, event, helper) {
        var recordId = cmp.get("v.recordId");
        var selectedTemplate = cmp.get("v.selectedTemplate");
        var qName = cmp.get("v.simpleRecord.Name");
        var pdfName = selectedTemplate;
        var vfPage = cmp.get("v.vfPage"); 
        var action = cmp.get("c.savePDF_Quote");
        action.setParams({
            "vfPage": vfPage, 
            "recordId" : recordId, 
            "selectedTemplate" : selectedTemplate, 
            "pdfName" : qName
        });
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                alert('Attachment saved successfully');
                
            }
            else if (state === "INCOMPLETE") {
                // do something
            }
                else if (state === "ERROR") {
                    var errors = response.getError();
                    if (errors) {
                        if (errors[0] && errors[0].message) {
                            console.log("Error message: " + 
                                        errors[0].message);
                        }
                    } else {
                        console.log("Unknown error");
                    }
                }
        });
        $A.enqueueAction(action);
    }
    
    
    
    
    
})