This is a very lengthy question since I want to explain exactly what is happening.
I have 2 V.F page and controller on SAMPLE object (V.F Page names : SampleObjectPage(SOP) and RedirectPage(RP)). Currently the SOP page is written to override both NEW/EDIT button. Also the view page is redirected to this SOP page with the help of RP page. The redirection is happening with the help of RP page since if we override the SOP page with the VIEW button then it is opening the record in the EDIT mode rather in the VIEW mode. This must be happening due to the way the code is written. It is opening up as below.
If the redirection is happening through 2 V.F pages, then it is in between showing the Standard page and then finally opening up the SOP page as below.
Now the second option which I tried was to remove the V.F page from the Standard page. And just redirect to the SOP V.F page upon clicking NEW/EDIT/CLONE buttons. But this is also creating issue upon clicking the Save/Cancel buttons. It is then again redirecting back to the SOP Page rather than Standard page due to the way the code is already written. I have tried many things to redirect it back to the Standard page but nothing succeeded.
Here I am just posting the part of code which works upon Save/Cancel buttons since full code is very long. I want that upon cancel/save it should redirect to standard page.
Controller
public class SampleOrderExtension{
public SampleOrderExtension soExtObj { get { return this; } private set; }
public Sample__c soRecord { get;set; }
public Sample_Detail__c slRecord{ get;set; }
public boolean recordSaved { get;set; }
public String recSaved { get;set; }
public String clone { get;set; }
public String edit { get;set; }
public list<User> currentUser { get;set; }
public boolean isStandardUser { get;set; }
public ZEND__c ZendRec { get;set; }
public SampleOrderExtension(ApexPages.StandardController stdController){
// std = stdController; //Added on 7/Oct/2016
fromAcc = false;
fromOpp = false;
notIsROR = false;
noZend = ApexPages.currentPage().getParameters().get('noZend');
recSaved = Apexpages.currentPage().getParameters().get('recordSaved');
clone = Apexpages.currentPage().getParameters().get('clone');
edit = Apexpages.currentPage().getParameters().get('edit');
accId = Apexpages.currentPage().getParameters().get('CFlookupfieldID_lkid');
oppId = Apexpages.currentPage().getParameters().get('oppId');
opptyId = Apexpages.currentPage().getParameters().get('CFlookupfieldID_lkid');
//There is a lot of code here to insert/save sample records
}
//Method written for Save button
public PageReference save(){
ZEND__c Z=New ZEND__c();
if(!isNullOrEmpty(oppId)){
soRecord.Opportunity__c = oppId;
soRecord.from_Opportunity__c = true;
}
//Some IF-ELSE Statements
PageReference pr = null;
try{
if(!isNullOrEmpty(zend)){
//Z=[select id from ZEND__c where Name=:zend limit 1];
//soRecord.ZEND__c = Z.id;
soRecord.ZEND__c = zend;
}
}catch(Exception e){
soRecord.ZEND__c = null;
}
if(!isNullOrEmpty(soRecord.Ship_to__c)){
if(soRecord.Status__c != 'Ready for Processing'){
soRecord.Status__c = 'Saved, Not Submitted';
}
if(edit == '1'){
update soRecord;
}else if(clone == '1'){
soRecord = soRecord.clone(false, true);
insert soRecord;
}else{
if(soRecord.ZEND__c==null){
}
insert soRecord;
}
recordSaved = true;
pr = Page.SampleOrderPage;
pr.getParameters().put('id', soRecord.Id);
pr.getParameters().put('recordSaved', 'true');
return pr.setRedirect(true);
}
return pr; //Need to modify this so that redirection happen to Standard Page.
}
public PageReference cancel(){
PageReference pr = null;
if(clone == '1' || edit == '1'){
pr = Page.SampleOrderPage;
pr.getParameters().put('id', soRecord.Id);
pr.getParameters().put('recordSaved', 'true');
pr.setRedirect(true);
}else{
pr = new PageReference('/object 3 digit id/o');
}
return pr; //Need to modify this so that redirection happen to Standard Page.
}
}
V.F Page
<apex:page standardController="Sample__c" extensions="SampleOrderExtension" sidebar="false" standardStylesheets="true" id="SampleOrderPage">
<apex:form id="mainForm">
<apex:outputPanel rendered="{!IF(recSaved == 'true' ,true, false)}"> //This part of code is just for the page which is displayed after save.
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton id="editBtn" value="Edit" rendered="{!NOT(statusRFP)}" action="{!editSampleOrder}" />
<apex:commandButton id="cloneBtn" value="Clone" action="{!cloneSampleOrder}"/>
<apex:commandButton id="cancelBtn" value="Cancel" rendered="{!NOT(statusRFP)}" action="{!cancel}"/>
<apex:commandButton id="submitBtn" value="Submit" rendered="{!NOT(statusRFP)}" onclick="ZendSumbitvalidation()" rerender="dummy, messagePanel"/>
<!--<apex:actionFunction name="ZendSumbitvalidation" action="{!updateStatus}" /> -->
</apex:pageBlockButtons>
<apex:pageBlockSection title="Sample Request Detail" columns="2" collapsible="false">
<apex:outputField id="outputSampleName" value="{!soRecord.Name}"/>
<apex:outputField id="outEndEquipment" value="{!soRecord.End_Equipment__c}"/>
<!--<apex:outputField id="outputAppName" value="{!soRecord.Application__c}"/>-->
<apex:outputField id="outEndCustomer" value="{!soRecord.End_Customer__c}" />
<apex:outputField id="outputSAPSales" value="{!soRecord.SAP_Sales_Order_Number__c}"/>
<apex:outputField id="outputCSO" value="{!soRecord.CSO__c}"/>
<apex:outputField id="outputStatus" value="{!soRecord.Status__c}"/>
<apex:outputField id="outputRSM" value="{!soRecord.RSM__c}"/>
<apex:outputField id="outputEmailContact" value="{!soRecord.Email_cc_Contact__c}" />
<apex:outputField id="outputPaidSample" value="{!soRecord.PAID_SAMPLE__c}" />
<apex:outputField id="outputEmailUser" value="{!soRecord.Email_cc_User__c}"/>
<apex:outputField id="outputSalesOrg" value="{!soRecord.Sales_Org__c}"/>
<apex:outputField id="outputSpecialShipping" value="{!soRecord.SPECIAL_SHIPPING_INSTRUCTION_COMMENTS__c}"/>
<apex:outputField id="outputPlatform" value="{!soRecord.Platform__c}"/>
<apex:outputField id="outputDistributorNote" value="{!soRecord.Distributor_Note__c}"/>
<apex:outputField id="outputaccOutput" value="{!soRecord.Account__c}"/>
<apex:outputField id="outputshipTofield" label="Ship to Contact" value="{!soRecord.Ship_to__c}"/>
<apex:outputField id="outputCustomerContact" value="{!soRecord.CUSTOMER_CONTACT__c}"/>
<div> </div>
<apex:pageblockSection id="inner1" columns="1" title="Customer Contact Address">
<apex:outputField label="Phone" value="{!soRecord.Customer_Contact_Phone__c}"/>
<apex:outputField id="outputContactAddress" label="Street/House Number" value="{!soRecord.Customer_Contact_Street_House_Number__c}"/>
<apex:outputField id="outputContactShippingCity" label="City" value="{!soRecord.Customer_Contact_City__c}"/>
<apex:outputField id="outputContactShippingState" label="State" value="{!soRecord.Customer_Contact_StateVisible__c}"/>
<apex:outputField id="outputContactShippingCountry" label="Country" value="{!soRecord.Customer_Contact_CountryVisible__c}"/>
<apex:outputField id="outputContactShippingPostalCode" label="Postal Code" value="{!soRecord.Customer_Contact_Postal_Code__c }"/>
</apex:pageblockSection>
<apex:pageblockSection id="inner2" columns="1" title="Ship To Contact Address">
<apex:outputField label="Phone" value="{!soRecord.Shipping_Phone__c}"/>
<apex:outputField id="outputAddress" value="{!soRecord.SHIP_TO_COMPANY_ADDRESS__c}"/>
<apex:outputField id="outputShippingCity" label="City" value="{!soRecord.ShippingCity__c}"/>
<apex:outputField id="outputShippingState" label="State" value="{!soRecord.Shipping_StateVisible__c}"/>
<apex:outputField id="outputShippingCountry" label="Country" value="{!soRecord.Shipping_CountryVisible__c}"/>
<apex:outputField id="outputShippingPostalCode" label="Postal Code" value="{!soRecord.ShippingPostalCode__c }"/>
</apex:pageblockSection>
<apex:outputField id="CreatedBy" value="{!soRecord.CreatedById}"/>
<apex:outputField id="LastModifiedBy" value="{!soRecord.LastModifiedById}"/>
<apex:outputField id="CreatedDate" value="{!soRecord.CreatedDate}"/>
<apex:outputField id="LastModifiedDate" value="{!soRecord.LastModifiedDate}"/>
</apex:pageblockSection>
<apex:pageBlockSection columns="1" id="compBlock">
<c:SampleOrderRLComponent soExt="{!soExtObj}"></c:SampleOrderRLComponent>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:outputPanel>
</div>
</apex:form>
</apex:page>
Is there any way to modify the code to redirect back to the Standard page ?
EDIT : Snip for how record shows up now after save and how I need.
NOW
Required



