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
TC AdminTC Admin 

Redirect User to newly created clone opportunity once finished editing

Hi All, I have a Apex class and VF Button that Clones an opportunity while overwritting certian fields.

Before lightening the user would be re-directed to their newly created opportunity after they press save on the edit page.
However since Lighting have taken away teh URL hacking it does not work.
Original URL hack:
return new PageReference('/'+newOP.id+'/e?retURL=%2F'+newOP.id);

I have dones some research and found I can use the below code however this BYPASSES the edit screen and takes them directly to the new cloned opportunity. meaning people cannot edit the new clone before actually saving.
return new PageReference('https://cs109.lightning.force.com/'+newOP.id);

Any ideas how I can combine the two so that when the user presses "Clone with items" They are taken to an edit screen. Once they press send they are taken to to newly created clone not just a blank page?
Khan AnasKhan Anas (Salesforce Developers) 
Hi,

Greetings to you!

You can use return new PageReference('/'+newOP.Id);

Below is the sample code to edit opportunities and it is working fine. Kindly modify the code as per your requirement.

Visualforce:
<apex:page standardController="Opportunity" extensions="OpportunityEditPageC" sidebar="false">
    <apex:form >
        
        <apex:outputPanel id="tstpopup">
            <apex:outputPanel styleClass="popupBackground" layout="block" rendered="{!displayPopUp}" />
            <apex:outputPanel styleClass="custPopup" layout="block" rendered="{!displayPopUp}" >
                <p> You have selected Warm Rating !!! </p>
                <apex:commandButton value="Ok" action="{!closePopup}" reRender="tstpopup" />
            </apex:outputPanel>
        </apex:outputPanel>
        
        <apex:pageBlock title="Opportunity Detail">
            <apex:pageBlockbuttons >
                <apex:commandButton value="Save" action="{!saveOpp}"/>
            </apex:pageBlockbuttons>
            <apex:pageBlockSection title="Opportunity Information 1" columns="2" collapsible="false">
                <apex:outputField value="{!accnt.OwnerId}" />
                <apex:inputField value="{!accnt.Name}"/>
                <apex:inputField value="{!accnt.Account.Name}"/>
                <apex:inputField value="{!accnt.DeliveryInstallationStatus__c}"/>
                <apex:inputField value="{!accnt.TrackingNumber__c}"/>
                <apex:inputField value="{!accnt.CloseDate}"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Opportunity Information 2" columns="2" collapsible="false">
                <apex:inputField value="{!accnt.Description}"/>
                <apex:inputField value="{!accnt.LeadSource}"/>
                <apex:inputField value="{!accnt.NextStep}"/>
                <apex:inputField value="{!accnt.Type}"/>                
                <apex:inputField value="{!accnt.StageName}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Controller:
public class OpportunityEditPageC {

    public Opportunity accnt {get;set;}
    public String oid;
    
    public OpportunityEditPageC(ApexPages.StandardController controller) {
        Opportunity temp = (Opportunity)controller.getRecord();
        oid = temp.Id;
        accnt = [SELECT Id, OwnerId, Name, StageName, Account.Name, DeliveryInstallationStatus__c, TrackingNumber__c, CloseDate, Description, LeadSource, NextStep, Type 
                 FROM Opportunity 
                 WHERE Id=:oid];
    }
    
    public pageReference saveOpp(){
        UPDATE accnt;
        return new PageReference('/'+accnt.Id);
    }
}

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
Raj VakatiRaj Vakati
This is what my understanding .. 

1 . lightening  PageRefernce URL redirect doest  work so i can suggest to create a create a component and do it .. 
2. Create a ligning compoenet to clone the records after clone the record navigate the lightning component using navigration APi and URL Addressable interface 
TC AdminTC Admin
Hi Khan Anas your solution is basically the same as my second URL. It just saves the new cloned opp I don't get an edit screen. I need it to go to the edit screen first.

Hi Raj Vakati I already have an apex code to clone the ops how do i use API anf URL addressable interface within the apex coding?