Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Salesforce
  3. Question
Salesforce

ActiveXObject is not defined [closed]

Asked by Bruce Benedict Apr 16, 2021 7.0K views 3 answers
Share

About this question

 I have an existing Javascript button that causes an "ActiveXObject is not defined" error when I click on it.

{ !REQUIRESCRIPT("/soap/ajax/22.0/connection.js") } var newIRnAGenRequest = new sforce.SObject("Account"); newIRnAGenRequest.id = "{!Account.Id}"; newIRnAGenRequest.Request_Folder_Path__c = "{!Account.Request_Folder_Path_Hidden__c}"; newIRnAGenRequest.Req_Communication_Folder_Path__c = "{!Account.Req_Communication_Folder_Path__c}"; newIRnAGenRequest.Primary_Request_Status__c = "{!Account.Primary_Request_Status__c}"; var result = sforce.connection.update([newIRnAGenRequest]); var myObject; var myFile0 = "{!Account.Request_Folder_Path_Hidden__c}"; var myFile1 = "{!Account.Req_Communication_Folder_Path__c}"; if (newIRnAGenRequest.Primary_Request_Status__c == "Submitted") { alert("Please select a Primary Team assigned"); } else { location.reload(true); myObject = new ActiveXObject("Scripting.FileSystemObject"); if (myObject.FolderExists(myFile0)) { window.open(myFile0); } else { var myObject2, newfolder; myObject2 = new ActiveXObject("Scripting.FileSystemObject"); newfolder = myObject2.CreateFolder(myFile0); newfolder = myObject2.CreateFolder(myFile1); window.open(myFile0); } }

When I try to google it, I found that it was related to files and it is dedicated to IE only. It worked a few months ago in chrome. But now it stopped working everywhere. My request is to provide any alternate solutions if ActiveXObject can't be used anymore.

Your answer

3 Answers

Ranjana Admin JanBask Expert Latest answer

Answered on Mar 17, 2025

If you're seeing the error "ActiveXObject is not defined", it usually means you're trying to use ActiveXObject in a browser that doesn’t support it. Here’s why it happens and how to fix it:

1. Why Are You Getting This Error?

  • ActiveXObject is only supported in Internet Explorer (IE).
  • Modern browsers (Chrome, Edge, Firefox, etc.) do not support ActiveX for security reasons.
  • If you're running the script in Node.js, ActiveXObject is not available.

2. How to Fix It?

✅ Solution 1: Use Internet Explorer (If You Must)

If you absolutely need ActiveXObject, run the script in Internet Explorer:

  var obj = new ActiveXObject("Scripting.FileSystemObject");

But keep in mind that IE is outdated and not recommended.

✅ Solution 2: Use an Alternative API

If you're working with file operations, use the File API in modern JavaScript instead:

let input = document.createElement("input");
input.type = "file";
input.onchange = (event) => {
    let file = event.target.files[0];
    console.log("Selected file:", file.name);
};
document.body.appendChild(input);

✅ Solution 3: Use PowerShell or Node.js for Windows Automation

If you need Windows automation, use PowerShell instead of ActiveXObject. Or, in Node.js, use the fs module:

const fs = require('fs');
fs.writeFileSync('test.txt', 'Hello, world!');

3. Final Thoughts

  •  ActiveXObject is outdated and should be avoided.
  •   Use modern alternatives like File API, Node.js, or PowerShell.
  •   If you must use it, run the script in Internet Explorer (not recommended).


Was this helpful?

Ranjana Admin JanBask Expert

Answered on May 8, 2024

The error message "ActiveXObject is not defined" typically occurs in a web environment when trying to use ActiveXObject in JavaScript, but the code is executed in an environment where ActiveX is not supported or enabled.


ActiveXObject is a proprietary Microsoft technology used for creating and interacting with objects in Internet Explorer, primarily for tasks like working with XML data or accessing system resources. It's not supported in modern browsers like Google Chrome, Firefox, Safari, or Microsoft Edge.

If you encounter this error, here are some steps you can take:

Use Modern APIs: Wherever possible, avoid using ActiveXObject and instead use modern, standardized APIs like XMLHttpRequest for AJAX requests or fetch API.

Check Browser Compatibility: Ensure that your code is being executed in a browser environment that supports ActiveX. If you're testing in a modern browser, it's likely that ActiveX is not supported.

Consider Alternatives: If you absolutely need to work with ActiveX controls, you may need to use Internet Explorer or a similar browser that still supports ActiveX. However, keep in mind that this is not a sustainable solution for modern web development.

Update Legacy Code: If you're maintaining legacy code that relies on ActiveX, consider updating it to use modern alternatives. There are often ways to achieve the same functionality using standard web technologies.

Implement Feature Detection: If you need to support both modern and legacy browsers, consider implementing feature detection to determine whether ActiveXObject is available before attempting to use it.


Here's a basic example of feature detection:

if (window.ActiveXObject) {
    // ActiveXObject is supported, proceed with code that uses it
} else {
    // ActiveXObject is not supported, provide alternative code or fallback
}

By following these steps, you can address the "ActiveXObject is not defined" error and ensure that your code works correctly across different browser environments.












Was this helpful?

More Salesforce discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Salesforce Blogs

Guides, tips and career advice on Salesforce from JanBask experts.