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
rosscorossco 

Overriding New Button for Custom Object

Hi I have a custom object (credit agreement) that has a lookup relationship to the Opportunity. I want to override the New button (for credit agreements) and retrieve values from the parental Opportunity. I have written a VF page that has a standard controller of the creditagreement__c and has extensions but in the extensions class I cannot seem to access the opportunity data. Help ! :) Many thanks to all in advance Ross
Navatar_DbSupNavatar_DbSup

 Hi,

 

You can pass the id of opportunity to which creditagreement__c  record is associated with while calling you VF page through the Custom Button as paramether like below:

 

/apex/yourVFPageName?id={! creditagreement__c.opportunity__c}

 

Now you can easily retrieve this value by using ApexPages.currentPage().getParameters().get(‘id’).

Id ids= ApexPages.currentPage().getParameters().get(‘id’);

 

Now you the id of opportunity make the query on opportunity object by using this id.

Opportunity op=[select id, other fields that you want from opportunity where id=:ids];

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

rosscorossco

Thanks for the response. 

 

Yes, this will work for a custom button, button I want to override the standard "New" button.

 

Ross

bob_buzzardbob_buzzard

I'm not sure you'll be able to do this via an override of the new button.  The thing is that the new button appears in a number of places - at the top of a list view for example.  At that point, there isn't an opportunity associated with the record, so if your override relies on one it won't work.