Users receive an error when clicking a custom button when using Internet Explorer web browser of;

"A problem with the ONClick JavaScript for this button or link was encountered:

Object doesn't support property or method 'startsWith'"

Note that this error only occurs when using Internet explorer.

The code for my custom button is below. Is there anything I can do to get this working?


var r = confirm("Warning: this will make the R&D Project or Service  available for Salesforce Opportunities, once they are added to a price list. Do  you wish to proceed?"); 
if(r==true) { 

var result = sforce.apex.execute("availableForOpportunities","convertToOpportunity", 

location.reload = '/'+result[0].Id+'/e'; 

// Check result in console window 

// If this result starts with a string equal to the id key for the object type you are accessing, relocate the browser to that page 

if (result[0].startsWith('001')) { 
location.reload = '/' + result[0] + '/e'; 
} else { 
// Otherwise, show the error message to the viewer 

Internet Explorer doesn't support the Javascript function startsWith yet. You can replace it with:

if (result[0].lastIndexOf('001', 0) === 0) {

The trick here is that the function lastIndexOf returns the last position of the substring found. But if you specify the index 0 as second parameter, it will start searching at position 0 but searching backwards. So it will return 0 if the string starts with the substring.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.