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
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!!!
GauravGargGauravGarg
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:
{!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/33.0/apex.js")} 

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]); 
if(result[0].getBoolean("success")) 
{ 
alert('Opportunity Created successfully'); 
window.location.reload(); 
} 
else{ 
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.

Thanks,
Gaurav
EldonEldon
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.

Regards
SArorasSAroras
Hi Eldon,

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

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