function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
BrenzoBrenzo 

Custom Javascript Button to Send Email Only Working for Certain Profiles

I have a custom buttong designed to execute javascript for sending an email in the background and then refreshing the page.

The problem I am running into is that the button works perfectly for myself and the other administrator, but simply refreshes the page for everyone else who clicks it.

Because of this, my assumption is that there must be a user setting or permission for the profile(s) of those who cannot trigger the button to send the email. I've gone through and turned settings on/off and tried to strip the button code down, but I still can't quite figure out what is causing this issue. My hunch says it's something with the SingleEmailMessage or sendEmail parameters of the code, but the user profile(s) in question have the abiltiy to send email and do just about everything else and they don't run into issues with other javascript codes.

Here is my code:
{!REQUIRESCRIPT("/soap/ajax/35.0/connection.js")} 
if( 
{!Contact.Outside_PartnerId__c = "a1sG0000005AeeS"}) 
{ 
var message = new sforce.SingleEmailMessage(); 
message.replyTo = "{!User.Email}"; 
message.targetObjectId = "{!Contact.Id}"; 
message.templateId = "00XG0000001cZKS"; 
message.saveAsActivity = true; 
var result = sforce.connection.sendEmail([message]); 
} 
else{ 
alert('This button is only available for sending to Company X reps.'); 
} 

//refresh the page 
window.location.reload();

I really appreciate anyone's help or insight into this.
Nilesh JNilesh J
Hi Brenzo,

Did you checked the field permission for Contact.Outside_PartnerId__c field on other profiles. That may be a reason to fail this functionality.
BrenzoBrenzo
Hi Nilesh,

Yes, that is a read-only formula field that is visible to all profiles. I went ahead and removed it from the code entirely, but that did not fix the issue. The page refreshes, but the email does not send.

I have also tested this button on contact records owned by the user, as well as those owned by others in the system, but that does not make a difference either.

So unfortunately I am still stuck. 
Pankaj_GanwaniPankaj_Ganwani
Hi Brenzo,

Please remove window.location.reload(); from the bottom of the script, click on the button with other profile(one which is causing issue) in google chrome and check in console(By inspect element in chrome) whether there are any errors coming or not.