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

Create Opportunity from Contact
I would like to be able to create an Opportunity from a Contact - using a VF page to limit the fields required for the Opportunity. I want to make sure the current Contact's Account is pre-populated as a read-only field. I would appreciate any direction on doing this.
I'm having some difficulty learning how to call a VF page and pass a Contact's ID when a non-standard controller is used on the VF page.
Thank you
I threw this together quickly but if you creat a button on the contact page to call this vf page you can creat a new opportunity and associate it to the account related to the contact.
you will have to clean up the save function to redirect to another page when done, etc, but it works.
VF Page:
VF Controller Extension
All Answers
You could user the Contact controller as a standard controller
Create a ContactControloler Extension
Private Contact thisCon;
Public ID idAcct{get;set;}
Public Opportunity oOpp;
in the initalizing of your controllerExtension
thisCon=(Contact)controller.getRecord();
init();
in your init() function:
get reference to current contact record
idAcct = [Select id, AccountID From Contact where id=: thisCon.ID].AccountID;
oOpp = New Opportunity(AccountID = idAcct);
In your VF Page:
Reference the fields on the Opportunity on your VF page
This may not be the shortest way to do it and assumes you are calling the page from the contact record.
For some reason, I still can't get this to work quite right. Could you please post your APEX code solution?
I threw this together quickly but if you creat a button on the contact page to call this vf page you can creat a new opportunity and associate it to the account related to the contact.
you will have to clean up the save function to redirect to another page when done, etc, but it works.
VF Page:
VF Controller Extension
Thank you. One part I'm missing is how can I force a field selection in the new Opportunity. For example, how can I force a specific stage name to be saved on the new Opportunity?
Change the construct of the new Opp to
oOpp = New Opportunity(AccountID = idAcct, StageName = '**your value here**');
And if you do not want them to change the value change the inputfield for StageName to:
<apex:Outputfield id="idC" value="{!oOpp.StageName}" />
Thank you. This has been very helpful!