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
Ravi_SFDCRavi_SFDC 

Save Button Issue

Having an issue i my Save Code. Code is as below

public PageReference doSave() {
        try{
        List<Unidentified_Deals__c> uds = new List<Unidentified_Deals__c>();
        for(oppWrap o:opps){
            if(o.check){
                Unidentified_Deals__c u = new Unidentified_Deals__c(Name=o.opp.Name,Opportunity__c=o.opp.Id, Account_Plan__c=accountPlanId, Account__c = o.opp.AccountId);
                uds.add(u);
            }
        }
        insert uds;
        upsert od;
        upsert lw;
        fetchOpps();
        ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.INFO, 'Saved and Refreshed!!');
        ApexPages.addMessage(myMsg);
        }catch(Exception e){
        ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.Error, e.getMessage());
        ApexPages.addMessage(myMsg);
        }
        return null;
    }
The content is getting saved, but only excuting the "Saved and Refreshed". I don't want to execute "Saved and Refreshed", i want the page to return to the previous page where i cam from. Your help is really appreciated.

Thanks & Regards
Ravi


 

Best Answer chosen by Ravi_SFDC
Ravi_SFDCRavi_SFDC
Solution is as below. This worked.
public PageReference doSave(){
        PageReference page = new PageReference('/'+ID);
        page.SetRedirect(true);
        return page;

All Answers

Manoj Maraka 18Manoj Maraka 18
Hey Ravi,

You need to modify your return statement to the code given below. comment out "return null" and replace with below code.
PageReference pref = new PageReference('/apex/YOUR_PREV_PAGE_NAME');

return pref;

PS: if this answers your question then hit Like and mark it as solution!
 
Ravi_SFDCRavi_SFDC
Hi Manoj, 

My URL is as https://myinstancename/a1819000000lunB on which i do have custom button. When i click on the cuctom button i do have the save button for the which the code is above. So when i click on SAVE button it should return to the https://myinstancename/id. I have commented the return null and provided your code, but this didn't work.
Manoj Maraka 18Manoj Maraka 18
Try this-
Replace sObject with your object and add this code in your class
sObject currentRecord = [SELECT Id FROM sObject WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
And modify the pageReference with below code
PageReference pref = new PageReference('/currentRecord.id');
return pref;

Hope this helps!!

 
Ravi_SFDCRavi_SFDC
No Manoj this didn't work.
Ravi_SFDCRavi_SFDC
Solution is as below. This worked.
public PageReference doSave(){
        PageReference page = new PageReference('/'+ID);
        page.SetRedirect(true);
        return page;
This was selected as the best answer