+ Start a Discussion
Dave SnowDave Snow 

Can OnClick JavaScript run in System Mode?

I am trying to use a custom button w/ JavaScript to execute a record update for users who would otherwise not be able to edit the record, due to permissions and record sharing.  However, when I click the button as a user without the proper edit rights on the record, nothing happens (except the page reload).  It works just fine when logged in as SysAdmin.
Is it possible to get the javascript to execute without regard to the logged in user's edit rights on the record?  If so, what am I missing?  Code is below:

{!REQUIRESCRIPT("/soap/ajax/34.0/connection.js")} 
var newRecords = []; 
var c=new sforce.SObject("Contact"); 
c.id="{!Contact.Id}"; 
c.Referral__c="True"; 
newRecords.push(c); 
result=sforce.connection.update(newRecords); 
window.location.reload();

Best Answer chosen by Dave Snow
sfdcsushilsfdcsushil
You may consider writing update in a class in webservice type method. Call that from javascript. Keep the class in Non Sharing mode. 

All Answers

sfdcsushilsfdcsushil
You may consider writing update in a class in webservice type method. Call that from javascript. Keep the class in Non Sharing mode. 
This was selected as the best answer
Dave SnowDave Snow
Thank you for the advice, Sushil!
HyTrust SupportHyTrust Support
My current custom "Send an Email" button, which is also located in a custom object is a OnClick JavaScript. The script is:

window.location = '/_ui/core/email/author/EmailAuthor';

For a particular profile, I still want the "Send Email" check box - unchecked under the Profile > General User Permissions.

I am not familar on how to write a webservice class as proposed by the previous post. Can someone provide details on what my script should look like to allow this custom button to "runAs" either System or another user/profile that can send email utilizing the OnClick JavaScript method?