You need to sign in to do that
Don't have an account?
Sunil
How to create new record into custom object using sControl
I want to use a custom link at Opportunity Object that creates a new record in custom object. I have written following code in sControl.
I am getting 'Object Expeceted' error in the line '<body onload="pageInit()">'.
Might be I am asking very basic questions but plz help me to solve this problem.
==================== Code Start ===================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>PVA Case: {!Opportunity.Name}</title>
<script language="javascript"
src="https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js"
type="text/javascript"></script>
<script type="text/javascript" src="/js/functions.js"></script>
<script type="text/javascript" src="/js/setup.js"></script>
<script type="text/javascript" src="/js/roletreenode.js"></script>
<script type="text/javascript" src="/js/sfdcPage.js"></script>
<script language="javascript">
function pageInit()
{
sforceClient.init("{!API.Session_ID}", "{!API.Partner_Server_URL_70}");
}
function saveRec()
{
var tru= new Sforce.Dynabean("Trust__c");
tru.set(“Name”, “Trust 7”);
tru.set("Opportunity","Test Case");
tru.set("GA__c", "Test GA");
tru.set(“GA_Address__c", "Test GA Address”);
tru saveResult = sforceClient.Create(tru)[0];
}
</script>
</head>
<body onload="pageInit()">
<TABLE>
<TR>
<TD><input value=" Save " class="btn" type="button"
title="Save" onclick="saveRec()" name="save"> <input value="Cancel"
class="btn" type="button" title="Cancel" onclick="window.close()" name="cancel"></TD>
</TR>
</TABLE>
</body>
</html>
<html>
<head>
<title>PVA Case: {!Opportunity.Name}</title>
<script language="javascript"
src="https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js"
type="text/javascript"></script>
<script type="text/javascript" src="/js/functions.js"></script>
<script type="text/javascript" src="/js/setup.js"></script>
<script type="text/javascript" src="/js/roletreenode.js"></script>
<script type="text/javascript" src="/js/sfdcPage.js"></script>
<script language="javascript">
function pageInit()
{
sforceClient.init("{!API.Session_ID}", "{!API.Partner_Server_URL_70}");
}
function saveRec()
{
var tru= new Sforce.Dynabean("Trust__c");
tru.set(“Name”, “Trust 7”);
tru.set("Opportunity","Test Case");
tru.set("GA__c", "Test GA");
tru.set(“GA_Address__c", "Test GA Address”);
tru saveResult = sforceClient.Create(tru)[0];
}
</script>
</head>
<body onload="pageInit()">
<TABLE>
<TR>
<TD><input value=" Save " class="btn" type="button"
title="Save" onclick="saveRec()" name="save"> <input value="Cancel"
class="btn" type="button" title="Cancel" onclick="window.close()" name="cancel"></TD>
</TR>
</TABLE>
</body>
</html>
======================== End Code ==========================
Thanks in advance.
also you had a typo on the Create() line, note it shoudl be
var saveResult not
tru safeResult
Code:
Thanks Ron. Now I am not getting any error at the time of page load.
I have implemented the same code as you have mentioned, now I am getting 'Exception error on line 1016' when I click on Save button.
I have put alter to check where the exception error is coming and alert is running fine before the following line: -
var saveResult = sforce.connection.create([tru]);
I am not able to figure out the problem. Any idea where is the problem?
Thanks.
try {
var saveResult = sforce.connection.create([tru]);
} catch(error) {
alert(error);
}
This should give you better error message.
Message Edited by cheenath on 05-01-2007 09:51 AM
Thanks. It was error of session. I have fixed it.
It is working now.
:-)