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
shan876shan876 

Insert a Record???

Hi I have the following code (below)... What I am trying to do is insert a new record or Case from a button without letting the user know on a particular ticket reason and detail... Now the code tells me it works... but I do not see any cases created when I refresh the ticket screen... does anyone know where am I wrong....Later I will override a the close button and place this s-control in...
Code:
<html> 
<head> 
<script type="text/javascript" language="javascript" src="/js/functions.js"></script> 
<script type="text/javascript" src="/soap/ajax/10.0/connection.js"></script> 
<script type="text/javascript"> 


function cCreate() { 

var cReason = "{!Case.Reason}"; 

var cDetail="{!Case.Reason_Detail__c}";

var cAccount = "{!Case.Account}";

var newURL="{!URLFOR( $Action.Case.CloseCase , Case.Id,[retURL=$Request.retURL] ,true)}" ; 



if (cReason=="Lockbox Request")
{
if (cDetail=="Fee") 
{ 
//Disable the Close button 
var cCase = new sforce.SObject("Case");
cCase.Paperwork_Incoming__c = "{!Case.Paperwork_Incoming__c}" ;
cCase.Account ="{!Case.Account}" ;
cCase.Status = "New";
cCase.Reason= "Lockbox Fee";
cCase.Subject= "{!Case.Subject}";
cCase.Description="{!Case.CaseNumber}";
  sforce.connection.create([cCase ]);
alert("done");
} 
else 
{ 
//Redirect to Close Edit Page 
alert("You Can not do this"); 
//window.parent.location.replace(newURL); 


} 
}
} 
</script> 
<style> 

.btn, .button, .formulaButton, .btnWhatsNew { 
font-family: 'Verdana', 'Geneva', sans-serif; 
background-repeat: repeat-x; 
background-position: left top; 
border-right:1px solid #5C5D61; 
border-bottom:1px solid #5C5D61; 
border-top:none; 
border-left:none; 
font-size: 80%; 
color:red; 
padding:1px 3px 1px 3px; 
cursor:pointer; 
font-weight:bold; 
display:inline; 
} 
</style> 
</head> 
<body> 
<form> 
<INPUT TYPE="button" class="btn" NAME="myButton" VALUE="Test" onClick="cCreate();"> 
</form> 
</body> 

</html>

 Thank You for your help
zishan
shan876shan876
well I updated my code and now I am getting an error on id.. do not understand what I did wrong...Plz Help
Code:
<html> 
<head> 
<script type="text/javascript" language="javascript" src="/js/functions.js"></script> 
<script type="text/javascript" src="/soap/ajax/10.0/connection.js"></script> 
<script type="text/javascript"> 


function cCreate() { 

var cReason = "{!Case.Reason}"; 

var cDetail="{!Case.Reason_Detail__c}";

var cAccount = "{!Case.Account}";

var newURL="{!URLFOR( $Action.Case.CloseCase , Case.Id,[retURL=$Request.retURL] ,true)}" ; 

if (cReason=="Lockbox Request")
{
if (cDetail=="Fee") 
{ 
//Disable the Close button 
var cCase = new sforce.SObject("Case");
cCase.ParentId = "{!Case.ParentId}";
cCase.CreatedById = "{!Case.CreatedById}";
cCase.AccountId = "{!Case.AccountId}";
cCase.Paperwork_Incoming__c = "{!Case.Paperwork_Incoming__c}" ;
cCase.Account = "{!Case.Account}" ;
cCase.Status = "New";
cCase.Reason = "Lockbox Fee";
cCase.Subject = "{!Case.Subject}";
cCase.Description = "{!Case.CaseNumber}";

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

if (result[0].getBoolean("success")) { 
alert("Its all Good "); 
} 
else 
{ 
alert("Fails on " + result[0] + ".  okkkkk"); 
} 
} 
else 
{ 
//Redirect to Close Edit Page 
alert("You Can not do this"); 
//window.parent.location.replace(newURL); 


} 
}
} 
</script> 
<style> 

.btn, .button, .formulaButton, .btnWhatsNew { 
font-family: 'Verdana', 'Geneva', sans-serif; 
background-repeat: repeat-x; 
background-position: left top; 
border-right:1px solid #5C5D61; 
border-bottom:1px solid #5C5D61; 
border-top:none; 
border-left:none; 
font-size: 80%; 
color:red; 
padding:1px 3px 1px 3px; 
cursor:pointer; 
font-weight:bold; 
display:inline; 
} 
</style> 
</head> 
<body> 
<form> 
<INPUT TYPE="button" class="btn" NAME="myButton" VALUE="Test" onClick="cCreate();"> 
</form> 
</body> 

</html>

 
shan876shan876

I figured it out...It works for those of you who want to insert a new record in a case on the fly here is the following code to do just that:

Code:
<html> 
<head> 
<script type="text/javascript" language="javascript" src="/js/functions.js"></script> 
<script type="text/javascript" src="/soap/ajax/10.0/connection.js"></script> 
<script type="text/javascript"> 


function cCreate() { 

var cReason = "{!Case.Reason}"; 

var cDetail="{!Case.Reason_Detail__c}";

var cAccount = "{!Case.Account}";

var newURL="{!URLFOR( $Action.Case.CloseCase , Case.Id,[retURL=$Request.retURL] ,true)}" ; 

if (cReason=="Lockbox Request")
{
if (cDetail=="Fee") 
{ 
var cCase = new sforce.SObject("Case");
cCase.ParentId = "{!Case.ParentId}";
cCase.AccountId = "{!Case.AccountId}";
cCase.Paperwork_Incoming__c = "{!Case.Paperwork_Incoming__c}" ;
/*cCase.Account = "{!Case.Account}" ;*/
cCase.Status = "New";
cCase.Reason = "Lockbox Fee";
cCase.Subject = "{!Case.Subject}";
cCase.Description = "{!Case.CaseNumber}";

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

if (result[0].getBoolean("success")) { 
alert("Its all Good "); 
} 
else 
{ 
alert("Fails on " + result[0] + ".  okkkkk"); 
} 
} 
else 
{ 
//Redirect to Close Edit Page 
alert("You Can not do this"); 
//window.parent.location.replace(newURL); 


} 
}
} 
</script> 
<style> 

.btn, .button, .formulaButton, .btnWhatsNew { 
font-family: 'Verdana', 'Geneva', sans-serif; 
background-repeat: repeat-x; 
background-position: left top; 
border-right:1px solid #5C5D61; 
border-bottom:1px solid #5C5D61; 
border-top:none; 
border-left:none; 
font-size: 80%; 
color:red; 
padding:1px 3px 1px 3px; 
cursor:pointer; 
font-weight:bold; 
display:inline; 
} 
</style> 
</head> 
<body> 
<form> 
<INPUT TYPE="button" class="btn" NAME="myButton" VALUE="Test" onClick="cCreate();"> 
</form> 
</body> 

</html>


 

rakesh muppirirakesh muppiri

<apex:pageshowHeader="false"standardController="login__c">

 <apex:form>

<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

<scriptsrc="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script>

<scriptsrc="../../soap/ajax/27.0/connection.js"type="text/javascript"></script><scriptsrc="../../soap/ajax/15.0/apex.js"type="text/javascript"></script>

<scripttype="text/javascript">
var __sfdcSessionId ='{!GETSESSIONID()}';
</script>

<scripttype="text/javascript">
function insertRec(){

           var name = document.getElementById('j_id0:j_id2:Name').value;
var pass = document.getElementById('j_id0:j_id2:password').value;
var login =new sforce.SObject("Login__c");


login.Name= name; login.password__c = pass;var newRecords =newArray(); newRecords.push(login); alert('here'+login);

            var delResult=sforce.connection.create(newRecords);


alert('here2');

            
if
(delResult[0].getBoolean("success")){


log("account with id "+ result[0].id +" deleted");

}else{ log("failed to delete account "+ result[0]);

            }


alert('loading....'+name);}

</script>

<div style="margin-left:5%;;margin-top:5%;">

<table>
<tr>
<td> Name </td>

      <td>:</td>
<td><apex:inputTextid="Name"/></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><apex:inputTextid="password"/></td>
</tr>
<tr>
<tdcolspan="3">
<apex:commandButtonstyle="margin-left:93px;" value="Insert" onclick="insertRec()"/>
</td>
</tr>
</table>
</div>
</apex:form>

</apex:page>
rakesh muppirirakesh muppiri

Sorry i'm posting my code again to good format, I'm also facing the problem while inserting a reocrd

 

<apex:page showHeader="false" standardController="login__c">

<script src="../../soap/ajax/27.0/connection.js" type="text/javascript"></script>
<script src="../../soap/ajax/15.0/apex.js" type="text/javascript"></script>
<script type="text/javascript">
var __sfdcSessionId = '{!GETSESSIONID()}';
</script>

<script type="text/javascript">
function insertRec(){
var __sfdcSessionId = '{!GETSESSIONID()}';
var name = document.getElementById('j_id0:j_id2:Name').value;
var pass = document.getElementById('j_id0:j_id2:password').value;
var login = new sforce.SObject("Login__c");
login.Name = name;
login.password__c = pass;
var newRecords = new Array();
newRecords.push(login);
alert('here'+login);
var delResult = sforce.connection.create([login]);
alert('here2');
if (delResult[0].getBoolean("success")) {
log("account with id " + result[0].id + " deleted");
} else {
log("failed to delete account " + result[0]);
}
alert('loading....'+name);
}
</script>
<apex:form >
<div style="margin-left:5%;; margin-top:5%;">
<table>
<tr>
<td> Name </td>
<td>:</td>
<td><apex:inputText id="Name"/></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><apex:inputText id="password"/></td>
</tr>
<tr>
<td colspan="3"><apex:commandButton style="margin-left:93px;" value="Insert" onclick="insertRec()"/></td>
</tr>
</table>
</div>
</apex:form>

</apex:page>