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
PrasunnaPrasunna 

Custom button automatically create opportunity

Hi All,

I created a custom object. I loaded some records in that. Now when we open any of that record i want to display a custom button when we click that it automatically create a opportunity. Can anyone have idea how to create custom button that will creatae the opportunity for that sales person?

Thanks in Advance,
Prasunna. 
Veenesh VikramVeenesh Vikram
Hi Prasunna,

You can make use of AJAX Toolkit to achieve the same.
https://developer.salesforce.com/docs/atlas.en-us.ajax.meta/ajax/

Example: we can have a button which executes below javaScript
{!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/33.0/apex.js")} 

var accnt = new sforce.SObject("Account");
accnt.Name = prompt('Enter new Account Name','{!Account.Name}');

var result = sforce.connection.insert([accnt]);
if(result[0].getBoolean("success"))
{
   alert('Account updated successfully');
   window.location.reload();
}
else{
  alert('Error : '+result);
}

Hope this helps!
Veenesh
PrasunnaPrasunna
Hi Veenesh,

Thanks for your response!

My scenario is to create custom button for custom object when we click on that custom button that will create opportunity for that record.

Thank you,
Pavithra.