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
saravana kumar 106saravana kumar 106 

Hi folks i am new to salesforce, need to replika lead object edit page and i done wih save function using controller based on my requirement, but i am not able to replicate save&view button

<apex:commandButton value="Save & New" action="{!recordSaveandNew}"></apex:commandButton>

public PageReference recordSaveandNew()
            {   
                convertLeadRecord();
                //this code will redirect to home page but i need to redirect new lead page
                PageReference pg =new PageReference(Url.getSalesforceBaseUrl().toExternalForm());
                return pg;
            }
Rounak SharmaRounak Sharma
hello saravana kumar,
if i am not wrong you want to save the record and redirect it to the lead rocord page. is it?
Please correct me if it is something else.
thanks
saravana kumar 106saravana kumar 106
Hi Rounak thanks for quick reply,

I need to show create new lead page after clicking, I am using vf standard controller page for lead edit and I replicate all view as it is salesforce default lead edit page,

after clicking Save & New button it should save update lead record and show neawlead creation page,

Expected page,
User-added image

based on my code am getting home page,
PageReference pg =new PageReference(Url.getSalesforceBaseUrl().toExternalForm());
                return pg;
User-added image

I need to load the expected page.

Thank again.



 
Ajay K DubediAjay K Dubedi
Hi Saravana,

I looked at your issue and found this solution. I have also mentioned the link from where I have got this solution.
It should work fine for you.

Link - https://developer.salesforce.com/forums/?id=906F000000095GEIAY

public PageReference saveAndNew(){
    try {
        save();
        
        Schema.DescribeSObjectResult result = ClassName.getRecord().getSObjectType().getDescribe();        
        PageReference pr = new PageReference('/' + result.getKeyPrefix() + '/e?' + queryString);
        pr.setRedirect(true);
        return pr;  

    } catch(System.DMLException e) {
        System.debug('Error - '+e.getmessage()+' in line number - '+e.getLineNumber());        
    }
}

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com