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
communitycommunity 

Override Save & new button

Hi All,

 

I have a custom object (XYZ__c) under Opportunities as a related list (master-detail).

 

I had to pre-populate few fields in XYZ record when user clicks on 'NEW XYZ' button under the opportunity.

 

So, I used a custom button and replaced the standard NEW XYZ button in the page layout (of opportunity) passing values in the URL.

 

.........&Name=Auto+Number&RecordType=****************&saveURL=/{!XYZ__c.Id}&retURL=/{!XYZ__c.Id}

 

Everything is fine. But when users click on Save and New, these values are not prepolating, instead it re-directs user to record type selection page !!!!!!!! Becoz, after save its going to the standard NEW button in the XYZ object, which I haven't overriden.  I just replaced the new button in the pagelayout (of opportunity). 

 

I cannot over-write the standard NEW button of XYZ object with URL. I dont have any VF pages. I just need couple of fields to be pre-populated hence i am using URL to override. 

 

Any help would be highly appreciated!

 

Please help.

Sonali BhardwajSonali Bhardwaj

You don't need to create a new custom button. You can just override  standard new. This will automatically work with Save and New also. But in this case you have to create a simple VF page which will just open your URL.

communitycommunity

Hey, thanks for the reply.

 

You mean to say that on page load of the VF page, it should be re-directed to that URL ? Then, it will create slight delay and re-direction of the page can be easily identified by the user. Don't you think it will be a problem ?

Sonali BhardwajSonali Bhardwaj

Yeah..thats right, there would be a slight delay. But there is no other option. When you override a New button you can override it with either scontrol or VF. you cannot develop scontrol in SF, so only VF option is left.

communitycommunity

Hey Sonali,

 

SO, I have used VF page to override the new button and used a controller to add logic to it. And yes, its working absolutely greate. Its getting re-directed to the required URL based on the conditions. Not much of delay though.

 

But, but, there is an issue.  When i click on New button.. fill in the fields.. click on save and new.. then its working like a charm.  If i open an existing record, click edit and then click on save and new button.. its showing a blank page!!! :-(

 

Am adding my controller code below. please help if am doing anything wrong.

 

 

 

 

public with sharing class CRFXYZ {

private XYZ__c LM;

    public CRFXYZ(ApexPages.StandardController stdcontroller) {
     this.LM= (XYZ__c)stdController.getRecord();
    }
    
    Public PageReference OnStart(){
    
    List<LookupObject__c> crf = [Select Id,Name,RecordTypeId from LookupObject__c where Id=:LM.Related_to_XYZ__c];
    if(crf.size()>0){

        /*logic here for redirection based on the recordtype of the lookupobject*/

    }

 

When i added debug, noticed that LM.Related_to_XYZ__c is NULL.  However, if i start from 'New' the list is not empty. Only when I click 'edit' and 'save and new', the ID is null and so is the list.

 

Help.Help!

 

 

Sonali BhardwajSonali Bhardwaj

When you override New, record (controller.getRecord()) would always be empty, it doesn't matter from where you are creating new.

 

You are creating a new record, how can you get its field values? I am not sure why this working for you in some cases. Please recheck it and find out why in some cases it has value?

sgkmillssgkmills

I have the same exact problem with a custom object and would like to know the answer to this.  Parameters get set if you click the 'new' button, but those same parameters don't get set when clicking the 'save and new' button from the edit button.