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
Shwetal DesaiShwetal Desai 

visual force pages not available for override standard button "New"

Hi

I have created one visual force page with Custom Controller
Now i want to override that page on standard button "New".
now when i click on "Override" link from setup it redirects me on proper page but there is no Visual Force pages available in dropdown list of Visual force pages.

What could be the problem?

any idea?

Thanks in Advance
Best Answer chosen by Admin (Salesforce Developers) 
Shwetal DesaiShwetal Desai

Yes, my problem is got solved. What do u facing in your VF page? the requirenment is:

We must use standardController and if you need to do any logical operation then you have to create apex class and use that apex class as an extensions on that vf page.

and you also need to do save/insert operation manually. 

All Answers

michaelforcemichaelforce
I had run into this problem as well, turns out you can only use a page to 'override' if it is using a standard controller for that object.  I got around it by overriding it with an s-control instead and the s-control simply redirects the browser to the desired visualforce address.  Not ideal, but it gets the job done.
jwetzlerjwetzler
Using an s-control is not the solution to this.  Yes in order to override the New action you must use a standardController.  If you want custom logic as well, that is what extensions are for.  Set the standardController to the object you need and turn the controller you developed into an extension.
Brendan LallyBrendan Lally
see also - http://community.salesforce.com/sforce/board/message?board.id=Visualforce&thread.id=3615

Lal
Shwetal DesaiShwetal Desai
Thank you all
 
Thanks Jill
 
My problem is solved by using extensions.
 
Thanks for all of urs help
Shwetal DesaiShwetal Desai
my old problem [overriding New button] is solved, but
after using extension m facing another problem
 
in my VF page i have used standard controller as well as extension ,now M not able to save record using stadard save method.
 
Do i need to override save() operation in extension?
Does standard save operation will not work even m using standardcontroller?
 
VF Code:
<apex:page StandardController="POSInvoice__c" extensions="POSInvoice" tabStyle="POS__c">
<!-- Start page content -->
<script type="text/javascript">
function openpopup()
{
    var test = window.open("{!$Page.giftcert}pos={!pos.id}&name={!pos.name}","_blank","width=670,height=390");  //eURL,"Sell Gift Certificate","height=250,width=350");
}
function savenew()
{
    window.location.href = "/a0Y/eretURL=%2F{!pos.id}&CF00N40000001aBUE_lkid={!pos.id}&CF00N40000001aBUE={!pos.name}";
}
</script>

<form  action="/apex/invoice" id="editPage" method="post" name="editPage" onsubmit="if (window.ffInAlert) { return false; }
        if (window.sfdcPage && window.sfdcPage.disableSaveButtons) { return window.sfdcPage.disableSaveButtons(); }" >
<apex:form >
<input type="hidden" name="cancelURL" id="cancelURL" value="/{!pos.id}" />
<input type="hidden" name="retURL" id="retURL" value="/{!pos.id}" />
<input type="hidden" name="save_new_url" id="save_new_url" 
    value="/a0Y/e˜retURL=%2F{!pos.id}&CF00N40000001aBUE_lkid={!pos.id}&CF00N40000001aBUE={!pos.name}" />
<div class="bPageBlock bEditBlock secondaryPalette" id="ep">
<div class="pbHeader">
<table  border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="pbTitle">
<img src="/s.gif" alt="" width="1" height="1" class="minWidth" title="" />
<h2 class="mainTitle">POS Invoice Edit</h2></td><td class="pbButton" id="topButtonRow">
<apex:commandButton id="save" value="Save" action="{!save}"/>
<apex:commandButton id="savenew" value="Save & New" onclick="savenew();return false;"/>
<apex:commandButton id="cancel" value="Cancel" action="{!cancel}"/>
<apex:commandButton onclick="openpopup();return false;" value="Sell Gift Certificate"/>
<apex:commandButton id="hold" value="Put On Hold" action="{!hold}"/>
</td></tr>
</table></div>

 
Apex Code:
public class POSInvoice 
{
    public ID posid{get; set;}
    private final POS__c pos;
    private final POSInvoice__c invoice;

    public POSInvoice(ApexPages.StandardController controller)
    {
        this.invoice = (POSInvoice__c)controller.getRecord();
        this.pos=[select Id,Name from POS__c where Id=:System.CurrentPageReference().getParameters().get('TId')];
    }
   
        public POS__c getpos()
        {
               return this.pos;
        }        
        public PageReference gift()
        {
            return Page.giftcert;
        }
        public void hold()
        {
            pos.OnHold__c = True;
            update pos;
            insert invoice;   
        }     
}

 Where i did wrong? please guide..
 
Also guide me to implement "Save & New" operation through commandbutton / standard method if any.
knicholsknichols
Did this get resolved?  I can't override my new button and I'm using the standard controller.
Shwetal DesaiShwetal Desai

Yes, my problem is got solved. What do u facing in your VF page? the requirenment is:

We must use standardController and if you need to do any logical operation then you have to create apex class and use that apex class as an extensions on that vf page.

and you also need to do save/insert operation manually. 

This was selected as the best answer
b.db.d

This answer is misleading. I realize that it is in line with the published API docs and all, but it _is_ possible to use a custom controller page to override a standard button. The _only_ validation happens in the page lookup, so using the following method, your custom controllers will work with standard buttons. 

Obviously this is going off the official Salesforce reservation, so it may void your warranty...

 

Create a visualforce page with only the following markup

        <apex:page standardController="[your object]" >

         </apex:page> 

 

Override the buttons.

 

change the content of your page to contain whatever you wanted, and using whichever controller you like. 

 

jwetzlerjwetzler
We plan on plugging this hole so please do not do this or your page may break later on.  You can use an extension to get any kind of custom logic you want so it is unnecessary to try to "trick" the page into doing what you want.
VidtaVidta
Hey, can u elaborate How did u manage using S-controls? Because I dn't see my page even in S-control. Thanks!