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
Cristian TrifCristian Trif 

button that creates a Quote and a Contract

Hello,
So the requirement is to reduce the button clicks so I need to create a button on the Opportunity Layout and when pressed should automatically create a Quote and a Contract related to the that opportunity and also redirect to a visualforce page that contains the Price, Model and the Brand of a vehicle. We have an custom object called, Vehicle so all the fields are in this object.
This is the page layout of Opportunities of where i want my button to be.
User-added image

and also the related lists where are Quotes and Contracts.

User-added image

Santosh Bompally 8Santosh Bompally 8
Hi Cristian, 

Use a javascript button for this, 
Use the below code for reference. 
{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/22.0/apex.js" )}
var connection = sforce.connection;
var neworder= new sforce.SObject("Order");
newopportunity.RecordTypeId="getId"
newopportunity.OpportunityId="{!Opportunity.Id}";
newopportunity.CloseDate=new Date();
var newContract= new sforce.SObject("Contract");
// Add Contractfields
result = sforce.connection.create([neworder,newContract]);
// Redirect to VF after this

 
Cristian TrifCristian Trif

So where you said var new Contract = new sforce.sObject("Contract");
// add contract fields.. here it means that i should add the required fields when creating a contract?

Also I need to create a Contract and Quote. Can i just replace instead of Order to be Quote instead?

Cristian TrifCristian Trif
and this code I can add in a Apex Class? between <script> ...</script> ? Sorry, i'm a newbie..
Santosh Bompally 8Santosh Bompally 8
Hi Cristian 
 here it means that  - i should add the required fields when creating a contract? - Yes 
Can i just replace instead of Order to be Quote instead? - Yes You can just make sure you're populating required fields. 
this code I can add in a Apex Class? -  Scripts cannot be added on Apex Class, Hence answer is No. 
Cristian TrifCristian Trif
And i can also add your code in the body of the Custom Button and select execute with javascript? would that work?