3

I hope this is a simple problem and I'm just missing something.

My Controller is something like this

public pagereference processtempcon(){
    //some code here
    delete record;
    pagereference p = apexpages.Currentpage();
    p.setredirect(true);
    apexpages.Message msg = new Apexpages.Message(ApexPages.Severity.Info,'Total Number of Records Processed:' + selectedtempcon.size());
    apexpages.addmessage(msg);
    return p; 
}

Which is not supported.Any Idea on this

1
  • 1
    Just remove p.setredirect(true); Apr 22 '13 at 12:50
2

So you want to reload the page an show some info in the message box. The setRedirect(true) parameter removes the info you want to show:

If set to true, a redirect is performed through a client side redirect. This type of redirect performs an HTTP GET request, and flushes the view state

I have created a simple example and it works fine:

Controller:

public with sharing class test1{
    public Integer myInt { get; set; }
    public test1(){
        myInt = 0;
    }
    public pagereference processtempcon(){
        pagereference p = apexpages.Currentpage();
        apexpages.Message msg = new Apexpages.Message(ApexPages.Severity.Info,'Total Number of reloads: ' + (myInt++));
        apexpages.addmessage(msg);
        return p; 
    }
}

Page:

<apex:page controller="test1">
    <apex:form >
        <apex:messages/>
        <apex:commandButton action="{!processtempcon}" value="Reload"/>
    </apex:form>
</apex:page>

Result:

enter image description here

2
  • If i remove p.setredirect(true),the deleted record is also existing in the redirected page.But here I don't wanna show the deleted record in the redirected Page
    – Eagerin Sf
    Apr 23 '13 at 7:32
  • @EagerinSf In your code you are reading the entries from the database into the list. Then you delete one record. Why don't you just refresh a list with records after delete? Something like: delete record; listWithRecords = [select x, y, From MyObject__c]; return null; Apr 23 '13 at 8:37
1

Unless you want to re-run the constructor you might be better off not returning a page reference in your function. It has the same result as returning the page reference for the current page. For example

public void processtempcon(){
    //some code here
    ApexPages.Message msg = new Apexpages.Message(ApexPages.Severity.Info,'Total Number of Records Processed:' + selectedtempcon.size());
    Apexpages.addMessage(msg); 
}

If you want to selectively return users to a different page or to the same page you can switch from a void return type to a PageReference return type, but just return null. For example

public PageReference processtempcon(){
    //some code here
    if(selectTempCon.isEmpty()) {
       return Page.AnotherPage;
    } else {
      ApexPages.Message msg = new Apexpages.Message(ApexPages.Severity.Info,'Total Number of Records Processed:' + selectedtempcon.size());
      ApexPages.addmessage(msg);
      return null; // keeps the user on the current page
    } 
}
1
  • Here Once the records are Processed, I need to delete the processed Records and show the Remaining Records, which are present in the same Page.
    – Eagerin Sf
    Apr 23 '13 at 7:22

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.