+ Start a Discussion
Mike_M_2Mike_M_2 

Is it possible to get Account from overridden New Opportunity button which executes visualforce page?

We had a 3rd party do a customization for us. They overrode the New Opportunity button with a button that invokes a visualforce page. The controller for this VF page marshalls the data and then creates an opportunity. The problem is when the user clicks the NEW Opportunity button from an Account screen. The Account Name is not autopopulated to the Opportunity.Is there any way to Access the Account Name within the controller for this page? This is the first line of that controller just to show that it does not extend the opportunity controller. 

public class OpportunityCreate extends BaseController {

BaseController is virtual.

Thanks 

ShirishaShirisha (Salesforce Developers) 
Hi Mike,

Greetings!

You can simply create the trigger to populate the Account Name when you are trying to create the Opportunity.

Please find the sample trigger code along with the test class:

https://naveendhanaraj.wordpress.com/2016/12/26/trigger-to-auto-populate-opportunity-name-with-account-name/

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
Mike_M_2Mike_M_2

Hi Shirisha,
I think I did not make my question clear. In your example, you do:

[select id , Name,Account.Name From Opportunity Where id in :oppIds]

If I do this, the Account.Name will always be NULL.  This is the problem. When the user selects NEW opportunity from the account screen, the AccountName is not populated into opps.Account.Name. This is because it is NOT the standard "NEW opportunity" button. Instead, the button invokes a VF page and some APEX code. Thanks!