[SalesForce] Custom Button is not working for other profile except admin

I've a custom javascript button, to update the field on same object. this is perfect working for admin user but not working for non admin user.

Code as;

{!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/19.0/apex.js")} 

if("{!Patient_Services__c.Service_Invoiced__c}"== "0" ) 
{
    if("{!Patient_Services__c.Who_to_Invoice__c}"=="Facility Account")
        {

                var c = new sforce.SObject("Patient_Services__c"); 
                c.id = "{!Patient_Services__c.Id}"; 
                c.Ready_for_Billing__c= "1"; 
                result = sforce.connection.update([c]); 
                window.location.reload();

        }
}

i'm try on profile finance user(not admin). The following permission for ready for billing field and object

Profile Permission for object; not given any access.

Permission set for object(User) : Read, Create, Edit, View All

Field accessibility for field : visible to page layout and profile.

when i click on custom button, the page is refreshed but field is not update.
Please suggest.

Best Answer

As you are saying all object permissions are present for the user, please check if the user has API permission available.

To function the OnClick JavaScript button permission the profile should have this permission enabled.

You can check this by going to Setup -> manage users -> profiles -> Under the "Administrative Permissions" area --> "API Enabled" check box.

Also you should update your code as below to capture the error message and display it as alert message. Based on the error message you can fix the issue.

{!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/19.0/apex.js")}
if ("{!Patient_Services__c.Service_Invoiced__c}" == "0") {
    if ("{!Patient_Services__c.Who_to_Invoice__c}" == "Facility Account") {

        var c = new sforce.SObject("Patient_Services__c");
        c.id = "{!Patient_Services__c.Id}";
        c.Ready_for_Billing__c = "1";
        var result = sforce.connection.update([c]);
        if (result[0].getBoolean('success')) {
            alert('success!'); //Just for testing, You can remove this
            window.location.reload();
        } else {
            alert('An error occurred updating this record:\n\n' + result[0].errors.message);
        }
    }
}
Related Topic