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

sforce is not defined
Hi,. I am trying to replicate the cook book recipe and I still get this error. Here is the script that I copied from the cook book. I tried this on IE and Firefox.
Thanks in advance for your help
*******************************************************************************************************************************
{!requireScript("/soap/ajax/20/connection.js")}
{!requireScript("/soap/ajax/20/apex.js")}
var idsToInsert = {!GETRECORDIDS($ObjectType.Account)};
var noteTitle = prompt("Please Enter the Note Title");
var noteBody = prompt("Please Enter the Body of the Note");
alert("Record length:" +idsToInsert.length);
if (idsToInsert.length) {
// Making a synchronous call to apex
var result = sforce.apex.execute("mcbangalore.Mass Note Insert", "insertNotes", {iTitle:noteTitle, iBody:noteBody, iParentIds:idsToInsert});
alert(result[0] + "inserted");
} else if (idsToInsert.length == 0) {
alert("Please select accounts to insert notes");
}
Try using
<script src="/soap/ajax/13.0/connection.js"></script>
<script src="/soap/ajax/20/apex.js"></script>
instead of
{!requireScript("/soap/ajax/20/connection.js")}
{!requireScript("/soap/ajax/20/apex.js")}
It seems that the syntax for add script is not valid in your code. Try out the code given below :
<apex:page>
<html>
<head>
<script src="/soap/ajax/20.0/connection.js"></script>
<script src="/soap/ajax/20.0/apex.js"></script>
<script>
sforce.connection.sessionId = '{!$Api.Session_ID}';
var idsToInsert = "{!GETRECORDIDS($ObjectType.Account)}";
var noteTitle = prompt("Please Enter the Note Title");
var noteBody = prompt("Please Enter the Body of the Note");
alert("Record length:" +idsToInsert.length);
if (idsToInsert.length)
{
// Making a synchronous call to apex
try
{
var result = sforce.apex.execute("mcbangalore.Mass Note Insert", "insertNotes", {iTitle:noteTitle, iBody:noteBody, iParentIds:idsToInsert});
}
catch(err)
{
alert(err + "inserted");
}
}
else if (idsToInsert.length == 0) {
alert("Please select accounts to insert notes");
}
</script>
</head>
</html>
</apex:page>
Hi Kum09/Pradeep. Thanks for responding..however I am now getting a syntax error when I try to run the code
Hey,
Can you just let me know what exactly are you doing? Creating a VF Page or any javascript customized code ona button or any S-Control. What exactly are you trying to do.
What I can say is sforce is defined by adding the scripts in the top:
<script src="/soap/ajax/13.0/connection.js"></script>
<script src="/soap/ajax/13.0/plsoql.js"></script>
<script src="/soap/ajax/13.0/functions.js"></script>
And with this also we need to set the session Id by putting this in our main script
var sId = '{!SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE($Api.Session_ID,'&','&'),'\'','’'),'"','"'),'<','<'),'>','>')}';
sforce.connection.sessionId = sId;
So your code will become like this :
<script src="/soap/ajax/13.0/connection.js"></script>
<script src="/soap/ajax/13.0/plsoql.js"></script>
<script src="/soap/ajax/13.0/functions.js"></script>
<script src="/soap/ajax/20/apex.js"></script>
<script>
var sId = '{!SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE($Api.Session_ID,'&','&'),'\'','’'),'"','"'),'<','<'),'>','>')}';
sforce.connection.sessionId = sId;
var idsToInsert = {!GETRECORDIDS($ObjectType.Account)};
var noteTitle = prompt("Please Enter the Note Title");
var noteBody = prompt("Please Enter the Body of the Note");
alert("Record length:" +idsToInsert.length);
if (idsToInsert.length) {
// Making a synchronous call to apex
var result = sforce.apex.execute("mcbangalore.Mass Note Insert", "insertNotes", {iTitle:noteTitle, iBody:noteBody, iParentIds:idsToInsert});
alert(result[0] + "inserted");
} else if (idsToInsert.length == 0) {
alert("Please select accounts to insert notes");
}
</script>
Try using this code. or tell me what exactly are you trying to do?
Charu
Hi Charu, thanks. I was trying to create a button and code via Javascript. My scripts were fine. The only problem was with my class definitions. If you notice, I had it defined as "Mass Note Insert" and this should have been "MassNoteInsert". The code works fine now. Thanks for all your help.