+ Start a Discussion
Barry Wang 11Barry Wang 11 

Create a New Opportunity button under Case Object

I want to create a button named "New Opportunity" that can create a new opportunity when click it. But I dont know how to make it happen,
plz help. Thanks very much!!!
Hi Barry,

This can be acheived through AJAX Toolkit on button click. Here is my solution:

Create a new button (New Opportunity) and select Display Type as Detail page Button Behaviour: Execute javascript
and paste below code in JS editor:

var Opp = new sforce.SObject("Opportunity"); 

//Add all mandatory fields here
Opp.Name = prompt('Enter new Opportunity Name'); 
Opp.StageName = prompt('Enter Opportunity stage');
Opp.Discount_Percent__c = prompt('Enter Discount');

var result = sforce.connection.create([Opp]); 
alert('Opportunity Created successfully'); 
alert('Error : '+result); 

Basically we are collecting Opportunity data and creating a record through ajax request. If the transaction is success it will alert with a message else it will throw an error.

Hi Barry,

If you want to create a new opportunity from case record you can make use of salesforce action which is a standard functionality instead of custom button. Please follow the below steps for that,

First go to edit layout page in the case object,

User-added image

Then in the quick actions drag the New Opportunity to under "Quick Actions in the Salesforce Classic Publisher" like below.

User-added image

Now you can create new opportunity from that action,

User-added image

Hope this helps. Let me know if you have any issues.

Hi Eldon,

I have tried adding it to Quick Actions, but its not visible on main screen. What could be the reason for this.

Lori MingioneLori Mingione
I have the same problem.  The quick action button was added but it not visible.  Anyone have an answer to this?