+ Start a Discussion
Debbie GrueterDebbie Grueter 

Replace the "New" button on the Opportunity Home Page with a Visual Force Page

I want to replace the New Button on the Opportunity Home Page with a visual force page.  As I don't want my users to have the option to create a new opportunity from the this opportunity page.  I want to enforce that they only create a new opportunity from a Contact Record.  Has somebody done this recently?  If so could you share the speciciications with me so that I can build this myself and save some time?
Vinit_KumarVinit_Kumar
It's very simple.Create VF page which would disppaly a message saying the users need to create Opportunity from a Contact record and override New button with it.

The VF page code would be something like below :-
<apex:page standardController="Opportunity">

<apex:form >
        <apex:pageBlock >
        <apex:pageMessage summary="Create Opportunity from Contact record" severity="info" strength="3" />
        <apex:pageMessages />

  </apex:pageBlock>
    </apex:form>
</apex:page>
If this helps,please mark it as best answer to help others :)
Ryan PadillaRyan Padilla
You might look at this stackexchange post (http://salesforce.stackexchange.com/questions/5716/override-new-button-and-redirect-to-vf-page-based-on-pagelayout-assignment) that provides an example of how to do conditional redirection using a custom vf page (not the same situation, the same principles apply).

If you just want to show an error message instead, you could do something like:

<apex:page title="Not Allowed" standardStylesheets="true" standardController="Opportunity">
        <div style="font-size: 16px; font-weight: bold; margin: 2em 0;">This operation should only be performed in the Contact Record Page</div>
</apex:page>

You could also add some javascript to redirect the page to the contact record after 5 seconds or so, but then you'd have to get the id of the Contact Record using an extension controller.
Ramu_SFDCRamu_SFDC
Create a visualforce page and assign the page to new button. This will open the visualforce when the user clicks on new button from  Opportunity home page or on Related list on other objects.

Below is an article on how to override standard pages

http://rjpalombo.com/2012/04/override-a-standard-salesforce-page-with-visualforce/

Hope this helps !!
Debbie GrueterDebbie Grueter
Hi Vinit, thank you so much. This worked; however, I can't seem to get the VF page to show in the drop down list when I got o override the standard buttons in the Opportunity Customize section. How do I get this show there. I am sure I am missing something simple. I appreciate all your help. I will mark it as the best answer to help others. :) *Debbie Grueter* CRM Analyst 26 Dartmouth Street Westwood, MA 02090 *O:* 781-251-2865 *E:* debbie.grueter@universalwilde.com Connect with us: Website | Blog | Facebook | LinkedIn
Vinit_KumarVinit_Kumar
If you have standardController="Opportunity",it should show up in the drop down.Can you see if you have standardController="Opportunity" in your VF page code.

somehting like :-

<apex:page standardController="Opportunity">
Debbie GrueterDebbie Grueter
I was able to add the VF page.  I was originally trying to add it the Opportunity Tab, under Buttons, Links and Actions; but it wasn't showing it there.  I then tried to add it to via the "New", and it was there;  however, it is no not working as expected.  As when I tried to add a new opportunity from a contact record, I keep getting the VF page message that I setup, and it won't let me add new.  I just keep getting the VF message.  I was hoping I could just block the user from creating a new opportunity from the Opportunity Home page;  but this VF page code is blocking me from creating a new opportunity period.  Is there something else I would need to add to do this?  I appreciate any help.  thanks
Vinit_KumarVinit_Kumar
Ok you need to do this,you need to remove your Standard New Button with custom 'New' button on Contact related List.Follow below steps :-

1.) Go to Setup -> Opportunity ->Button,Links,Actions -> Click on New

Create a button with Following attributes 

Display Type = List Button
Behaviour = Display in existing window without sidebar or header
Content Source= URL

Then,the URL box put this code 

/006/e?CF00N90000004mprm={!Contact.Name}&CF00N90000004mprm_lkid={!Contact.Id}&retURL=%2F{!Contact.Id}

Name and Save this button.

2.) Now go to Contact Layout ->Edit -> Go to related List Opportunity -> Click on Sign just beside (-)sign which says Related List Properties -> Click on buttons in new Window - > Uncheck the New button -> Under Custom buttons select the button you just created 

Save this Layout and you are good to go :)

If this helps,please mark this as best answer to help others :)
Debbie GrueterDebbie Grueter
Hi Vanit, thanks again for your suggestion.  I did create the new opportunity button like you mentioned above, however, with the current VF Page I also created per your first suggestion, I am still getting the same message when I use the new  Custom Create New Opportunity Button from the Contact Page record;  so it appears it the VF page on the Opportunity to replace the standard New button on the Opportunity Tab, is overriding everything and not allowing any create new opportunity at all.  Any other suggestions?  As my main objective is still only allow the creating of a new opportunity from a contact record.  Thanks again for all your help.
Pawan Sharma 12Pawan Sharma 12
Hi,

I am also facing same issue, is there any luck?
Pawan Sharma 12Pawan Sharma 12
Hi Debbie Grueter,
Did you find any solution?
GCS SalesGCS Sales
@Debbie Grueter, did you try to  to stop the override by using the nooverride parameter?

Ex: 
if(user.Profile.Name.equals(PARTNER_PROFILE)){ PageReference pr = new PageReference('/partner/006/e?retURL=%2Fpartner%2F006%2Fo&nooverried=1'); return pr;