+ Start a Discussion
SFDC coderSFDC coder 

Pass Values from one page to another without using query string params

Hi,

I would like to know if there is any  way  to pass values to another VF page  other than  passing it from Query String parameters?

If we want to pass a list of records then passing each field through query string parameters won't be a right way

Thanks,
Neha Patil
Best Answer chosen by SFDC coder
Tony TannousTony Tannous
Neha ,
this is a small example how to pass the accountids as parameters and in the next page you just need to split(',') and then do the select.

public with sharing class VFC01_Account
{

public list<Account> listAcc= new list<Account>();


public VFC01_Account ()
{
  listAcc=[select id,name
                 from Account
                  limit 10];
}
public PageReference DoRedirect()
{

         PageReference retVal= Page.Page2VF;
    
          string AccountIds='';
         foreach( Account acc :listAcc)
        {
                AccountIds +=acc.Id+',';
        }

          retVal.getParameters().put('AccountIds', AccountIds);
          retVal.setRedirect(true);
 
      return retVal;

}
}

All Answers

Tony TannousTony Tannous
Dear Neha,

You can use the same class controller and the list of record will keep the records while passing from a page to another.

check this link it will give you a clear vision 

http://www.salesforce.com/us/developer/docs/pages/index_Left.htm#StartTopic=Content/pages_quick_start_wizard.htm

Good Luck

SFDC coderSFDC coder
hi tony,
Apart from this is there any ohter way to share the data of one page to another page?

Regards,
Neha Patil
Tony TannousTony Tannous
Hi,


In case you can't use the same controller , the solution is to pass the Ids of the list in one parameter using query string and in the other VF page you need to do select on these ids to have the list again.

Regards
SFDC coderSFDC coder
how do i pass all the ids in one parameter?can u elaborate?...It will consider all those ids as  a single string..won't it?
Vishant ShahVishant Shah
HI Neha,

If it is happening in a single execution order you can try to use static variables

Ta
Vish
Tony TannousTony Tannous
Neha ,
this is a small example how to pass the accountids as parameters and in the next page you just need to split(',') and then do the select.

public with sharing class VFC01_Account
{

public list<Account> listAcc= new list<Account>();


public VFC01_Account ()
{
  listAcc=[select id,name
                 from Account
                  limit 10];
}
public PageReference DoRedirect()
{

         PageReference retVal= Page.Page2VF;
    
          string AccountIds='';
         foreach( Account acc :listAcc)
        {
                AccountIds +=acc.Id+',';
        }

          retVal.getParameters().put('AccountIds', AccountIds);
          retVal.setRedirect(true);
 
      return retVal;

}
}
This was selected as the best answer