+ Start a Discussion

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.


ShirishaShirisha (Salesforce Developers) 
Hi Mike,


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:


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

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!