Mitigating View State and Heap Size Constraints in Large-Scale Enterprise Visualforce Applications: A JavaScript Remoting–Based Architecture
Main Article Content
Abstract
Large-scale enterprise applications built on the Salesforce Platform frequently combine Visualforce pages with Apex controllers to support complex, data-intensive business workflows. As such applications grow in interaction complexity, two platform-level constraints become increasingly difficult to manage: the Visualforce view state size limit and the Apex heap size limit. This paper presents an architecture, developed and applied in a production enterprise Salesforce application supporting a multi-object business workflow, for eliminating recurring view state exceptions and improving page responsiveness. The root cause is traced to a common Visualforce implementation pattern in which apex:actionFunction action methods — constrained by the platform to return a PageReference rather than data — write their results into persistent, non-transient controller variables that are never cleared, causing the view state’s contribution from these variables to accumulate across a user’s session until the 170 KB limit is exceeded, while also incurring a full view-state round trip on every interaction. The proposed architecture relocates this data retrieval to JavaScript Remoting calls that return data directly, and migrates the associated rendering logic from server-side Visualforce/Apex tag rendering to client-side JavaScript-driven rendering, bypassing the view state entirely. We describe the design, implementation pattern, and operational trade-offs of this approach, and discuss its applicability to other Salesforce applications facing similar constraints. The approach eliminated the recurring view state exceptions in the application studied and improved page responsiveness, without requiring a migration away from the underlying Visualforce framework.
Downloads
Article Details
References
Guide, Salesforce Developers. [Online]. Available: https://
developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/
pages_best_practices_perf_view_state.htm
[2] Salesforce, “Salesforce Developer Limits and Allocations Quick
Reference,” Salesforce Documentation. [Online]. Available:
https://resources.docs.salesforce.com/latest/latest/en-us/sfdc/
pdf/salesforce_app_limits_cheatsheet.pdf
[3] B. Cline, “How To Reduce Visualforce’s View State,” brcline.
com, Mar. 2017.
[4] Salesforce, “Execution Governors and Limits,” Apex Developer
Guide, Salesforce Developers.
[5] A. Rivas, “New Resources for Moving from Visualforce to
Lightning Web Components,” Salesforce Developers Blog, Jul.
2020. [Online]. Available: https://developer.salesforce.com/
blogs/2020/07/new-resources-for-moving-from-visualforceto-
lightning-web-components
[6] Salesforce, “JavaScript Remoting Limits,” Visualforce Developer
Guide, Salesforce Developers. [Online]. Available: https://
developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/
pages_js_remoting_limits.htm
[7] Salesforce, “JavaScript Remoting for Apex Controllers,”
Visualforce Developer Guide, Salesforce Developers. [Online].
Available: https://developer.salesforce.com/docs/atlas.en-us.
pages.meta/pages/pages_js_remoting.htm
[8] K. Bowden, Visualforce Development Cookbook, 2nd ed.
Birmingham, UK: Packt Publishing, 2016.
[9] C. Isakson, “How To: Visualforce Javascript Remoting,” Sundog
Interactive Blog, Jan. 2014.
[10] Salesforce, “apex:actionFunction,” Visualforce Component
Reference, Salesforce Developers. [Online]. Available: https://
developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/
pages_compref_actionFunction.htm
[11] S. Saurabh, “Demystifying the PageReference,” writeforce.
blogspot.com, Aug. 2014.
[12] P. Runeson and M. Höst, “Guidelines for conducting and
reporting case study research in software engineering,”
Empirical Software Engineering, vol. 14, no. 2, pp. 131–164, 2009.[13] A. N. Topalli, “Learn MOAR in Spring ‘20 with Field Level Security
in Apex,” Salesforce Developers Blog, Jan. 2020. [Online].
Available: https://developer.salesforce.com/blogs/2020/01/
learn-moar-in-spring-20-with-field-level-security-in-apex
[14] Salesforce, “Using the transient Keyword,” Apex Developer
Guide, Salesforce Developers. [Online]. Available: https://
developer.salesforce.com/docs/atlas.en-us.apexcode.meta/
apexcode/apex_classes_keywords_transient.htm
[15] C. D. Weissman and S. Bobrowski, “The design of the force.
com multitenant internet application development platform,”
in Proc. 35th ACM SIGMOD Int. Conf. Management of Data
(SIGMOD ‘09), Providence, RI, USA, 2009, pp. 889–896, doi:
10.1145/1559845.1559942.
[16] J. J. Garrett, “Ajax: A New Approach to Web Applications,”
Adaptive Path, Feb. 2005. [Online]. Available: https://
adaptivepath.org/ideas/ajax-new-approach-web-applications/
[17] A. Mesbah, A. van Deursen, and S. Lenselink, “Crawling Ajax-
Based Web Applications through Dynamic Analysis of User
Interface State Changes,” ACM Transactions on the Web, vol.
6, no. 1, art. 3, 2012, doi: 10.1145/2109205.2109208.
[18] J. Cito, P. Leitner, T. Fritz, and H. C. Gall, “The Making
of Cloud Applications: An Empirical Study on Software
Development for the Cloud,” in Proc. 10th Joint Meeting on
Foundations of Software Engineering, 2015, pp. 393–403, doi:
10.1145/2786805.2786826.
[19] B. A. Kitchenham, S. L. Pfleeger, L. M. Pickard, P. W. Jones,
D. C. Hoaglin, K. El Emam, and J. Rosenberg, “Preliminary
Guidelines for Empirical Research in Software Engineering,”
IEEE Transactions on Software Engineering, vol. 28, no. 8, pp.
721–734, 2002, doi: 10.1109/TSE.2002.1027796.
[20] J. Siegmund, N. Siegmund, and S. Apel, “Views on Internal
and External Validity in Empirical Software Engineering,” in
Proc. 37th IEEE/ACM International Conference on Software
Engineering, 2015, pp. 9–19, doi: 10.1109/ICSE.2015.24.
[21] Salesforce, “RemoteAction Annotation,” Apex Developer Guide,
Salesforce Developers. [Online]. Available: https://developer.
salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/
apex_classes_annotation_remoteaction.htm
[22] F. S. Ocariza Jr., K. Bajaj, K. Pattabiraman, and A. Mesbah,
“An Empirical Study of Client-Side JavaScript Bugs,” in Proc.
ACM/IEEE International Symposium on Empirical Software
Engineering and Measurement, 2013, pp. 55–64, doi: 10.1109/
ESEM.2013.19.