You need to sign in to do that
Don't have an account?

Sforce is not defined
I get "Sforce is not defined" error message on the following code for mass completing tasks. The button is executing Javascript.
If the user has "View all Data" permission, I do not get the error message.
I read somwhere that AJAX libray is not being loaded and including {!REQUIRESCRIPT("/soap/ajax/12.0/connection.js")}; should fix it. But it doesn't.
Interesting, "mark complete" code for single task works okay - so i suspect there is an interaction with GETRECORDIDs.
This code for markcomplete works okay:
If the user has "View all Data" permission, I do not get the error message.
I read somwhere that AJAX libray is not being loaded and including {!REQUIRESCRIPT("/soap/ajax/12.0/connection.js")}; should fix it. But it doesn't.
Interesting, "mark complete" code for single task works okay - so i suspect there is an interaction with GETRECORDIDs.
Code:
/* This code allows the javascript to access the API and push data into the Org.*/ {!REQUIRESCRIPT("/soap/ajax/12.0/connection.js")}; sforce.connection.session = "{!$Api.Session_ID}"; function massCompleteTasks( ) { var taskArray = {!GETRECORDIDS( $ObjectType.Task )}; if (taskArray == null || taskArray.length == 0) { alert("Please select the tasks you wish to close."); return; } else { var newTaskArray = new Array(); for (var i = 0; i < taskArray.length; i++) { var newTask = new sforce.SObject("Task"); newTask.Id = taskArray[i]; newTask.Status = "Completed"; newTaskArray.push(newTask); } } var callCompleted = false; try { var result = sforce.connection.update(newTaskArray); callCompleted = true; } catch(error) { alert("Failed to update Tasks with error: " + error); } if (callCompleted) { for (var i = 0; i < result.length; i++) { if (!result[i].getBoolean("success")) { alert("Task (id='" + newTaskArray[i] + "') could not be updated with error: " + result[i].errors); } } window.location.reload(true); } } massCompleteTasks();
Code:
* This code allows the javascript to access the API and push data into the Org.*/ {!REQUIRESCRIPT("/soap/ajax/12.0/connection.js")}; sforce.connection.session = "{!$Api.Session_ID}"; function updateTask( ) { try { var task = new sforce.SObject("Task"); task.Id = "{!Task.Id}"; task.Status = "Completed"; var result = sforce.connection.update([task]); if (result[0].getBoolean("success") == false ) { alert(result[0].errors.message); return; } window.top.location.href=window.top.location.href; } catch (e) { alert(e); } } updateTask();
The error pop says:
A problem with the onClick Javascript for this button or link was encountered:
sforce is not defined
No I haven't debugged.
I need to figure out how to debug Javascript. I get the issue both in Firefox and IE.
Requirescript must be resolving itself since it works okay with the singe task complete (second piece of code)
I am not sure what you mean by "context of your first Scontrol is causing it not to resolve".
In both cases, I have defined a button with OnClick Javascript (technically no s-control).
The use case is slightly different - for "Mass Complete" one is selecting multiple tasks. For "Mark complete", it is the detail page of a task.
What would be the solution?
Message Edited by GoForceGo on 07-11-2008 04:32 PM
Is this a bug Salesforce has introduced in Summer 08?
Without "Enable Enhanced List", I can find my javascript in the main script on the page.
With it turned on, I can't even see the definitions of buttons. I am no Javascript/DOM expert, so I don't know where they are hidden and where to find my OnClick Javascript.
But more importantly, I am wondering what the solution is!
Message Edited by GoForceGo on 07-11-2008 06:03 PM
why
When I installed Firebug, there are a bunch of tabs on HTML, script.
Finding the OnClick Javascript code - I found it when I turn off "Enable Enhanced List". I can't find it when it is on.
When I did find it with "Enable Enhanced List" turnedd off, all the script is on one line. I can't set break points at each line.
I was hoping to set some breakpoints to what's going on.
http://www.evotech.net/blog/2007/06/introduction-to-firebug/
Really you'll probably want to use the debugger keyword. Just put a line somewhere in your code that says nothing but:
debugger;
And the code will break to the debugger right there.
If it is of any relevance, I am using the Professional edition with API enabled, so my ability to modify permissions outside of the default roles is pretty limited.
Code for this button was borrowed from a sample in the SF cookbook:
Message Edited by blittler on 07-27-2008 03:08 PM
I found a fix on this forum page: http://forums.sforce.com/sforce/board/message?board.id=apex&thread.id=1540
It appears that the "includes" for connection.js and apex.js are automatically placed on pages if you logon as a System Administrator (or via "logon as another user' as a Sys Admin), but not for "normal" users. Adding the REQUIRESCRIPT lines fixes this.
There's a better description of the problem I was experiencing in this blog post.
Message Edited by jrotenstein on 07-29-2008 11:43 AM
I tried adding Apex.js and it doesn't change anything.
As I mentioned, the problem doesn't happen if you disable "Enable Enhanced Lists". So there is some connection there...
Hi, I am also getting the same error while clicking on a hover link of a List button. In general, if i click on the related list button, javascript is working fine. But, if i'm going throuh the hover link of that related list and clicking on the same button, this error is being displayed.
This problem is only for IE, and for one sandbox. ame code deployed in another sandboxes works fine.
Please help.
Thanks in advance,
Suvra
hi..
continuing to the previous msg, i would like to put my script over here for your ref.
{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")}
alert('Hi1');
var accId = '{!Account.Id}';
var queryResult = sforce.connection.query("Select Id from Client_Brief__c where Account__c = '" + accId + "'");
var records = queryResult.getArray("records");
alert('Hi2');
if(records.length != 0)
{
alert('Please use the existing Client Brief for this Account');
}
else
{
var clientBriefObjId = sforce.apex.execute("SuperViewConstant","getclientBriefObjId",{});
window.top.location = "/"+clientBriefObjId+"/e?retURL=%2F{!Account.Id}&saveURL=/apex/ClientBriefSaveUrl?accid={!Account.Id}&nooverride=1";
}
For the normal related list button click, all alerts are being displayed. But for the hover link button click, only 'Hi1' is displayed and after that the error msg appears.
Hi..
Actually this issue was appearing because of the feature "Enable separate loading of related lists" which was released with the latest editiion of salesforce. Disabling that feature solves the problem as of now, although that's not the proper way out of this.
Thanks & Regards,
Suvra
Add {!REQUIRESCRIPT("/support/console/26.0/integration.js")} in code if you are facing issue in Service Console.