Problem with OnClick JavaScript for Button - Answers - Salesforce Trailblazer Community
Trailblazer Community
Ask Search:
Award MortgageAward Mortgage 

Problem with OnClick JavaScript for Button

I have a button in Opportunity. And salesforce users are able to click it, while for partner community users, it worked well before, but we are having issues since 1 or 2 weeks ago.

And the error is :
A problem with OnClick JavaScript for this button or link was encountered. 
{faultcode: 'sf:INVALID_TYPE', faultstring:'INVADLID_TYPE: Select A_IsActive__c from showButton__c'

I will paste the button JavaScript as below.
Thanks for any help.

{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/24.0/apex.js")}
var popupWindow;
var previousOnFocus;
var previousOnClick;

function parent_disable() {
if(popupWindow && !popupWindow.closed) {
popupWindow.focus();
} else if(popupWindow && popupWindow.closed) {
window.onfocus = previousOnFocus;
window.onclick = previousOnClick;
}
}

function openModel(pageURL) {
var w = (window.innerWidth * 30 / 100);
var h = (window.innerHeight * 40 / 100);
previousOnFocus = window.onFocus;
previousOnClick = window.onClick;
window.onfocus = parent_disable;
window.onclick = parent_disable;
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
popupWindow = window.open(pageURL,'Workspace',
'height='+h+',width='+w+',top='+top+',left='+left+',toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,modal=yes');
popupWindow.focus();
}

var ReferraAccepted = sforce.connection.query("Select A_IsActive__c from showButton__c");

records = ReferraAccepted.getArray("records");
if(records != null){
if(records[0].A_IsActive__c == 'true'){
openModel('/apex/SelectInstanceVF?oppId={!Opportunity.Id}');
}
}


 
Best Answer chosen by Award Mortgage
Award MortgageAward Mortgage
Thanks, I have already found out, just need to add a custom setting in Enabled Custom Setting Definitions Access.
 

All Answers

Gauthier MuguerzaGauthier Muguerza
Hello Award,

You have to give access to the new Custom Object and Visualforce page from the user's profile. And you have to check the "Customize Application" checkbox under the same profile.

Meanwhile, please be aware that JavaScript buttons are not supported in Lightning Experience!

Please have a look at these links:

- Problem with an OnClick JavaScript webservice (https://salesforce.stackexchange.com/questions/132484/problem-with-an-onclick-javascript-webservice)

- INVALID_TYPE:sObject (https://developer.salesforce.com/forums/?id=906F00000008qG6IAI)

- Lightning Alternatives to JavaScript Buttons (https://trailhead.salesforce.com/content/learn/modules/lex_javascript_button_migration)

Let me know if this helps :-)

Best,

Gauthier
Award MortgageAward Mortgage
Hi Gauthier, 

Thanks for your help, I checked the profile and found that only salesforce user have the authority of  customize application.

However, I am having issue with partner community users, it worked well for them before, and this error just happened in these weeks.

Any ideas?
Award MortgageAward Mortgage
Thanks, I have already found out, just need to add a custom setting in Enabled Custom Setting Definitions Access.
 
This was selected as the best answer