You need to sign in to do that
Don't have an account?
arasu
Appreciate is anyone can help identify the cause for this. This is my js code for the custom button:
Why is my custom button javascript code not working in sandbox?
Hi,
I have a custom button that executes a javascript code when clicked. It works fine for all user profiles in production, but does not work in sandbox and throws the following error message:
[object Error]-sforce.apex is null or not an object
It works in sanbox only for administrator profile.
Appreciate is anyone can help identify the cause for this. This is my js code for the custom button:
Javascript Code for the custom button:
{!requireScript("/soap/ajax/11.1/connection.js")} try{ var userid = '{!User.Id}'; var username='{!User.Name}'; var userEmail='{!User.Email}'; var apprId='{!Fixture_Order__c.Approver_Name__c}'; var fixOrder='{!Fixture_Order__c.Id }'; var vtoemailid='BHN.fixtures@bhnetwork.com'; var args = {puser:userid,pusername:username,puseremail:userEmail,pfixorderno:fixOrder,papprId:apprId,pemailtype:2,ptoEmailid:vtoemailid,pisruntest:false}; var result = sforce.apex.execute('HandlerFOSendEmail' , 'sendMail', args); if(vCardKitsNeeded==1){ var args = {puser:userid,pusername:username,puseremail:userEmail,pfixorderno:fixOrder,papprId:apprId,pemailtype:3,ptoEmailid:vtoemailid,pisruntest:false}; var result = sforce.apex.execute('HandlerFOSendEmail' , 'sendMail', args); } if(vMerchReq==1){ var args = {puser:userid,pusername:username,puseremail:userEmail,pfixorderno:fixOrder,papprId:apprId,pemailtype:4,ptoEmailid:vtoemailid,pisruntest:false}; var result = sforce.apex.execute('HandlerFOSendEmail' , 'sendMail', args); } alert("The fixture order has been sent to BHN Fixtures."); }catch(e) { alert("Send Email has failed. Please contact your system administrator with this screeshot or error message: "+e + "-" + e.message); }
From help:
You can specify which users can execute methods in a particular top-level Apex class based on their profile. These permissions only apply to Apex class methods, such as Web service methods, or any method used in a custom Visualforce controller or controller extension applied to a Visualforce page. Triggers always fire on trigger events (such as insert or update), regardless of a user's permissions.
NoteIf a user has the "Author Apex" permission enabled in his or her profile, the user has access to all Apex classes in the associated organization, regardless of the security setting for individual classes.
Permission for an Apex class is checked at the top level only. For example, if class A calls class B, and a user profile has access only to class A but not class B, the user can still successfully execute the code in class A. Likewise, if a Visualforce page uses a custom component with an associated controller, security is only checked for the controller associated with the page. The controller associated with the custom component executes regardless of permissions.
Hi Mike,
Thanks for your response. But I checked thoroughly and all access permissions for all classes and visualforce pages has been granted for all user profiles. I noted that it works only for System Administrator profile and not any other profile.
The behaviour is the same in both sanbox and production.
This is a critical issue for us now and greatly appreciate any help to identify the cause on why it throws the above error for all user profiles except system administrator.
Thanks and regards,
Ambili
And/Or does the class reference any objects in salesforce that users don't have CRUD on?
Thanks for your response. I added the following two lines of code at the beginning of the code and it worked!
{!REQUIRESCRIPT("/soap/ajax/10.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}
Thanks and regards,
Ambili