0

i am creating a button which will create new record. this is my code

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 


var curnc= new sforce.SObject("TR_Currency_Approval__c"); 
curnc.Name="{!TR_Currency__c.Name}"; 
curnc.Active__c="{!TR_Currency__c.Active__c}"; 
curnc.Description__c="{!TR_Currency__c.Description__c}"; 

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


if(result[0].success == 'true'){
    alert('An New Currency with Name - ' + TR_Currency__c.Name + ' was Created Successfully.');
}

Please let me know any errors,

8
  • I don't see any error. Is it working? Mar 2, 2017 at 9:46
  • not working martin, button is not at all responding Mar 2, 2017 at 9:48
  • this is not an answer, I think you should try to do it otherwise and avoid using javascript on button click (remember read about it, that is deprecated)
    – benahm
    Mar 2, 2017 at 9:51
  • Try to add a condition if there is no success like this:if(result[0].success == 'true'){...}else{alert(result[0].errors[0]);}. Like this you'll be able to get the error message. Mar 2, 2017 at 9:51
  • I tried by giving else condition also, not working, please let me know is there any other way to create a new record by onclick of button Mar 2, 2017 at 10:00

1 Answer 1

0

Try this

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 


var curnc = new sforce.SObject("TR_Currency_Approval__c");
curnc.Name="{!TR_Currency__c.Name}"; 
curnc.Active__c="{!TR_Currency__c.Active__c}"; 
curnc.Description__c="{!TR_Currency__c.Description__c}"; 

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

if(result[0].getBoolean("success")){
    alert('An New Currency with Name - ' + TR_Currency__c.Name + ' was Created Successfully.');  //Opening the record in edit mode if the record insert is successfull
    window.location = "/"  + result[0].id + "/e";   //Opening the record in edit mode if the record insert is successfull
}
else{
    alert('Could not create record' + result);
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .