0

My VF page is

<apex:PageBlock title="Letters" mode="inlineEdit"  >
<apex:pageBlockButtons location="top" rendered="{!IF(TasklstI.size>0,true,false)}" >
    <apex:commandButton value="Save" action="{!saveTaskI}" id="saveButton"/>
    <apex:commandButton value="Cancel" action="{!cancelTask}" id="cancelButton"/> 
</apex:pageBlockButtons>
<apex:pageblockTable value="{!TasklstI}" var="tsk" rendered="{!IF(TasklstI.size>0,true,false)}" id="table">

<apex:column headerValue="Document Type"> <apex:outputfield value="{!tsk.HBC_Grp_Task_Document_Type__c}"/></apex:column>
<apex:column headerValue="Group #"><apex:outputField value="{!tsk.HBC_Group_Num__c}"/></apex:column>
</apex:pageblockTable>
</apex:pageblock>

My Apex class for save and cancel is

   Public pagereference saveTaskI(){    
        Upsert tasklstI;
        ownerhide = false;

        pagereference pp = new pagereference('/apex/RecertificationDetails?id='+apexpages.currentpage().getparameters().get('id'));
        pp.setredirect(true);
        return pp;
      //return apexpages.currentpage(); the saved values are not displaying in the page
    }
    public pagereference cancelTask(){
         Pagereference pg = new pagereference('/apex/RecertificationDetails?id='+apexPages.currentpage().getparameters().get('id')); 
        pg.setredirect(true);
        return pg;
        //return apexpages.currentpage(); the values are not reverting back in the page
    }

I don't want to use such a lengthy code as it effects the performance.But If I use return apexpages.currentpage(); the page is not working as expected . Am I missing anything?

  • for using this, apexpages.currentpage(); you should also use apexpages.currentpage().getParameters.put('id',recordId); to set the updated value. – Rohit Mourya Apr 5 '17 at 11:03
  • Can you explain a little bit more as I'm not putting these recordid anywhere – Eagerin Sf Apr 5 '17 at 11:18
  • Refer the answer – Rohit Mourya Apr 5 '17 at 11:25
0

Though you want to use return apexpages.currentpage();, You've to set Page paramters. Refer below example:

PageReference pageRef = ApexPages.CurrentPage();
Apexpages.Currentpage().getParameters.put('id',ApexPages.Currentpage().getparameters().get('id'));
pageRef.setRedirect(true);
return pageRef;

Other method

pageRef = new PageReference('/apex/RecertificationDetails');
pageRef.setRedirect(true);
pageRef.getParameters().put('question',ApexPages.Currentpage().getparameters().get('id'));
return pageRef;
  • I just don't want to use those all lines. can i Just use like this Public pagereference saveTaskI(){ return apexpages.currentpage(); } as I was in the same page – Eagerin Sf Apr 5 '17 at 14:20
  • @EagerinSf As fas as I know. You can't do that because you need to setRedirect as true and update page parameters if you want to send any. That's how it works. – Rohit Mourya Apr 5 '17 at 14:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.