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
FreshFresh 

Standard Users receiving error when running Javascript

Hi all,

I'm new to Javascript, and I wrote a code that is creating a case, filling in fields, saving the case, and then bringing the user to the edit screen. This script works perfectly as long as I'm logged in as an Admin, works perfectly if I'm logged into a Standard User through Admin Login access, but when I actually sign out of SFDC and sign in as my test user, I'm receiving the error message:

'A Problem with the OnClick JavaScript for this button or link was encountered: 'sforce' is undefined'

The code is below:

--------------------------------------------------------------
var cCase = new sforce.SObject("Case");
cCase.AccountId = "{!Account.Id}";

//Emails
cCase.RecordTypeId = "012500000009RrS";
cCase.Ajilon_CC_Email__c = "{!Account.Ajilon_CC_Email__c}";
cCase.Ajilon_FOL_Email__c = "{!Account.Ajilon_FOL_Email__c}";
cCase.E_T_Email__c = "{!Account.ET_Email__c}";
cCase.General_Staffing_Email__c = "{!Account.General_Staffing_Email__c}";
cCase.LHH_Email__c = "{!Account.LHH_Email__c}";
cCase.Subject = "Account Team Request for {!$User.FirstName} {!$User.LastName} on {!Account.Name}";

var createResult = sforce.connection.create([cCase]);

if (createResult[0].getBoolean("success"))
{
var TheEditPage = "/" + createResult[0].id + "/e";
window.parent.location.href = TheEditPage;
}
else
{
alert("Operation Failed")
//Find a way to display error. Maybe use window.alert()
}

---------------------------------------------------------------

If anyone has run into this before, or can figure out what is causing this and how I can fix it, it would be very much appreciated.

Thanks in advance!
FreshFresh
Hi all,

I figured out what the issue was, apparently the Ajax toolkit does not load for users that do not have the "View All Data" permission, so you have to put a line in the custom button that loads it for them. The line of code is below:

{!requireScript("/soap/ajax/11.1/connection.js")}

I hope this helps a frustrated rookie developer in the future =)