Problem
When opening the Solution Console or performing actions within it (adding products, configuring solutions, navigating between components), JavaScript errors occur that prevent the console from functioning correctly. Common error messages include:
TypeError: Cannot read properties of undefined (reading 'forEach')
TypeError: Cannot set properties of undefined (setting 'remoteName')
Uncaught ReferenceError: [variable] is not defined
The Solution Console may:
- Fail to load completely
- Display a blank screen
- Show product configurations but prevent interaction
- Throw errors when clicking on products or attributes
Root Cause
Custom JavaScript code in the Salesforce org is directly manipulating DOM (Document Object Model) elements or global JavaScript variables that are used by the CloudSense Solution Console framework. This interference causes the Solution Console's internal state to become corrupted or undefined.
Common sources of interference include:
- Custom JavaScript in Visualforce pages that runs in the same context as the Solution Console
- Global JavaScript variables defined in custom code that conflict with CloudSense variable names
- Custom event listeners or DOM manipulation that modifies Solution Console elements
- JavaScript code in custom components that executes before CloudSense initialization completes
Resolution
Step 1: Identify Custom JavaScript Code
- Navigate to Setup > Custom Code > Visualforce Pages
- Search for Visualforce pages that include custom JavaScript:
- Look for pages with
<script>tags - Look for pages that include custom static resources with JavaScript
-
Focus on pages that are loaded in the same context as the Solution Console
-
Review each page for:
- Global variable declarations (e.g.,
var remoteName = ...) - DOM manipulation code (e.g.,
document.getElementById(),$('.class').remove()) - Event listeners that target Solution Console elements
- Code that runs on page load before CloudSense initialization
Step 2: Isolate the Interfering Code
- Open the browser's Developer Console (F12)
- Navigate to the Sources tab
- Set breakpoints in custom JavaScript files
- Reload the Solution Console
- Step through the code execution to identify where the interference occurs
- Note the specific code block or function causing the issue
Step 3: Fix the Custom Code
Apply one or more of the following fixes depending on the interference type:
Fix A: Namespace Global Variables
If custom code defines global variables that conflict with CloudSense:
-
Wrap custom code in an Immediately Invoked Function Expression (IIFE):
javascript (function() { // Your custom code here var remoteName = 'myValue'; // Now scoped locally })(); -
Or use a custom namespace:
javascript var MyCustomNamespace = MyCustomNamespace || {}; MyCustomNamespace.remoteName = 'myValue';
Fix B: Avoid Direct DOM Manipulation
If custom code manipulates DOM elements:
-
Add defensive checks before accessing elements:
javascript var element = document.getElementById('myElement'); if (element) { // Safe to manipulate } -
Use more specific selectors to avoid CloudSense elements:
javascript // Instead of: $('.product-item').remove(); // Use: $('.my-custom-class .product-item').remove(); -
Delay DOM manipulation until after CloudSense initialization:
javascript window.addEventListener('load', function() { setTimeout(function() { // Your DOM manipulation here }, 2000); // Wait for CloudSense to initialize });
Fix C: Remove Conflicting Event Listeners
If custom code adds event listeners that interfere:
-
Use event delegation with specific target elements:
javascript document.getElementById('myCustomContainer').addEventListener('click', function(e) { // Handle only clicks within your custom container }); -
Check event targets before processing:
javascript document.addEventListener('click', function(e) { if (e.target.matches('.my-custom-class')) { // Safe to process } });
Step 4: Test the Fix
- Save the updated Visualforce page or static resource
- Clear your browser cache
- Reload the Solution Console
- Test all affected operations:
- Add products to the basket
- Configure product attributes
- Navigate between solution components
-
Activate orders
-
Verify no JavaScript errors appear in the browser console
- Confirm all Solution Console functionality works as expected
Step 5: Deploy to Production
- If testing was done in a sandbox, deploy the fixed code to production:
- Use change sets, or
-
Use Salesforce CLI/metadata API
-
Test in production with a representative user
- Monitor for any recurring errors
Prevention
For Salesforce Developers
- Namespace All Custom Code: Always wrap custom JavaScript in namespaces or IIFEs to avoid global scope pollution
- Avoid Direct DOM Manipulation: Use Salesforce platform features (Lightning components, Visualforce component libraries) instead of direct DOM manipulation
- Defensive Programming: Always check for element existence before manipulating DOM
- CloudSense Compatibility Testing: Test custom JavaScript in the same context as CloudSense components to identify conflicts early
For Salesforce Administrators
- Code Review Process: Establish a code review process that checks for global variable conflicts and DOM manipulation before deploying custom JavaScript
- Sandbox Testing: Always test custom code changes in a sandbox with CloudSense components before deploying to production
- Documentation: Maintain a list of global variables and DOM elements used by custom code to avoid future conflicts
For Implementation Teams
- Best Practices Documentation: Document JavaScript best practices for your org, including namespacing conventions and CloudSense compatibility guidelines
- Training: Train developers on CloudSense framework architecture and how to avoid interference
- Static Analysis: Use JavaScript linting tools (ESLint, JSHint) to detect global variable declarations and potential conflicts
Related Information
- Affected Components: CloudSense Solution Console (Angular and React versions)
- Common Error Types:
TypeError,ReferenceError,Uncaught Exception - Related Concepts: JavaScript scope, DOM manipulation, event delegation, IIFE, namespacing
- Tools: Browser Developer Console, Salesforce Developer Console
- Best Practices: Salesforce JavaScript Best Practices
Priyanka Bhotika
Comments