function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Big_BBig_B 

Override Opportunity New button with error message unless creating from a contact page

I have been tasked with implementing a method to only allow users to create opportunities from a contact record so we can track campaign and other contact related information.  My thought is to override the opportunity 'New' button so that it displays an error message to the user if they click the New button from any other page than the Contact page.

Does anyone have any sample code to do this?  I have seen Java used to pop up alerts from a button.  Would that be the route to go?  How can I tell what page/record the 'New' button is being clicked from?

I have done some VF and Apex coding and still very green but very willing to learn so I may need a bit more explaination of the code than the average poster.

Thanks in advance!
Ashish_SFDCAshish_SFDC
Hi , 


In the UI the new button on the object or the related list or the quick create will redirecrt to the Create pageof the Object, there is no way to determine from where it is called. 

But in the VF page or page layout you can remove the button for set of users. 

Try debug logs / debugger and IDE to see if you can see any meta data change. 


Regards,
Ashish