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
Karina ChangKarina Chang 

Passing parameters to JavaScript

On an Opportunity, I have created a button to execute Javascript using sforce.apex.execute (I am calling an Apex Class).
The apex class creates a Contract record. I would like to get the record id (of the Contract just created) displayed on an alert after clicking on the button if creation is successful.
_______

{!RequireScript("/soap/ajax/34.0/connection.js")}
{!RequireScript("/soap/ajax/34.0/apex.js")}

function success() {
    // Indicate success
    var alertString="Success!"; 
    window.open('www.google.com');

    alert(alertString); 
}
function error() {
    // Indicate failure
    //window.open('www.yahoo.com');
    var alertString="Fail!"; 
    alert(alertString); 
}
sforce.connection.sessionId = "{!$Api.Session_ID}";
sforce.apex.execute("InsertContractAndPO", "createContractAndPOAsset",
{ accountId: "{!Opportunity.AccountId}", opportunityId: "{!Opportunity.Id}" }, 
{ onSuccess:success , onFailure: error});



 
Best Answer chosen by Karina Chang
Nayana KNayana K
function success(result) {
    // Indicate success
    var alertString="Success!"+result; 
    window.open('www.google.com');

    alert(alertString); 
}
function error(err) {
    // Indicate failure
    //window.open('www.yahoo.com');
    var alertString="Fail!"+err; 
    alert(alertString); 
}
I hope createContractAndPOAsset method's return type is ID or String. 
function success(result) { // result will hold the returned value I think. 

please try once 

All Answers

Nayana KNayana K
function success(result) {
    // Indicate success
    var alertString="Success!"+result; 
    window.open('www.google.com');

    alert(alertString); 
}
function error(err) {
    // Indicate failure
    //window.open('www.yahoo.com');
    var alertString="Fail!"+err; 
    alert(alertString); 
}
I hope createContractAndPOAsset method's return type is ID or String. 
function success(result) { // result will hold the returned value I think. 

please try once 
This was selected as the best answer
Karina ChangKarina Chang
Thanks Nayana! it worked.