You need to sign in to do that
Don't have an account?

button that creates new Quote
Hi,
I need to create a custom button on Opportunity Layout then when this button is pressed I need to create a new Quote and redirect to a VF page that I will create afterward. Someone can help me with this, please? I wrote some code but I don't know if it's good or bad.
Just need to create a new Quote on the current Opportunity which I'm in.
public class MyController { public String currentRecordId {get;set;} public String parameterValue {get;set;} public Opportunity opp {get;set;} public MyController(ApexPages.StandardController controller){ currentRecordId = ApexPages.currentPage().getparameters().get('id'); opp = [Select id From Opportunity where id =: currentRecordId]; parameterValue = ApexPages.currentPage().getparameters().get('nameParam'); Quote qo = new Quote(); insert qo; } }
copy paste below code -
All Answers
Step 1 : Create a visualforce page Step 2 : Create a controller extension
Step 3 : Create custom button of the type detail page button and include the same vf
Let me know if you face any difficulties
so basically in the doInsert method I will include my logic something like:
//create new Quote and add the required fields
Quote qt = new Quote();
qt.ContracTNumber='0001';
....
....
//after this insert the object
insert qt;
Similar to this i should write in this method?
As you can see I'm trying to also create a Contract as well related to that Opportunity but it does not create anything... I think the problem is at ct.AccountId = opp.id; I'm not sure how to make a relation between the Account name... do you know how?
So use -
ct.Accountid = opp.AccountId
It works man. Thanks! And one final thing, I need to change the StageName of the opportunity when I'm pressing this button.
I added: opp.StageName = 'Qualification'; but it doesn't change. You know why?
copy paste below code -
add opp.accountid.
Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.
Thanks
Varaprasad
@For Support: varaprasad4sfdc@gmail.com
Blog: http://salesforceprasad.blogspot.com/
Salesforce latest interview questions :
https://www.youtube.com/channel/UCOcam_Hb4KjeBdYJlJWV_ZA?sub_confirmation=1