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
Lalitha SelvarajLalitha Selvaraj 

pass apexpage message as parameter to pagereference

Hi i have a custom button on detai page.On click opens a VF page - where i have a save button.
On click of save , it inserts sme records. so after that i have to return to detail page.which i can.
But i want is the "Thank You! (n) Records inserted" some thing like this message.
Rupal KumarRupal Kumar
hi Lalitha,
      try this-
Page****

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


Conroller****

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; 
    }
}

Thanks
Rupal kumar
http://Mirketa.com
 
Lalitha SelvarajLalitha Selvaraj
Hi Rupal.. No this will not move to detail page .. For ex: i have to go back to detail page and display this message.is that possible?
Renuka NagarajRenuka Nagaraj
Using javascript remoting we can accomplish the task. sample code snippet is given below.

Page code :
<input type="button" value="saveRecord" onclick="saveRecord()" />

    <script type="text/javascript">
    function saveRecord() {
    
        Visualforce.remoting.Manager.invokeAction(
            '{!$RemoteAction.ControllerName.saveRecord}'
            function(result, event){
                if (event.status) {
                    
                    // alert here to show the count of records inserted  ( result.size )
                    // use setTimer javascript method to redirect to the detail page with certain delay( setTimeout(function(){ javascript for page redirection }, 3000);)
                } else if (event.type === 'exception') {
                        ...
                } else {
                   .....
            }, 
            {escape: true}
        );
    }
    </script>

    
Controller code :

  public static List<Account> lstAccounts { get; set; }

 @RemoteAction
    global static List<Account> saveRecord() {
        lstAccounts = [SELECT Id, Name, Phone, Type, NumberOfEmployees 
                   FROM Account ...];
        return lstAccounts;
    }
Rupal KumarRupal Kumar
try this-
public with sharing class test1{
    public Integer myInt { get; set; }
    public test1(){
        myInt = 0;
    }
    public pagereference processtempcon(){
       
    PageReference orderPage = new PageReference('/force_OrderDetail?id=' + order.id');//detail page url with record id
    orderPage.setRedirect(true);  
    
     ApexPages.addmessage(new ApexPages.message(ApexPages.severity.info,'Your record  has been submitted'));
      return orderPage;
    }
}
Thanks
Rupal kumar