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
SFDC_LearnerSFDC_Learner 

Query string parameters - List of Ids passing from one page to another page

Hi 

 

 

To pass the list of ids from one page to another we use the query string with pagereference statement.

 

like this return (new pagereference('/apex/mytestpage?cityVal='+cityValue+'&locationVal='+locationVal).setredirect(true));

 

Instead of passing individually  can we passa list variable

 

List<String> params = new List<String>();

params.add(cityValue);

params.add(locationVal);

 

then i pass this list in query string there in next page i get this id and split the values then i use.

 

Is this possible?

Best Answer chosen by Admin (Salesforce Developers) 
Hengky IlawanHengky Ilawan

Hi SFDC_Learner,

 

Yes you can pass the list in the query string. You can use JSON serialize methods and pass the json string to the query string. Then on the next page, you just deserialize it back to the original data type.

 

List<String> params = new List<String>{'cityvalue','locationVal'};
String sParams = System.JSON.serialize(params);

List<String> dParams = (List<String>)System.JSON.deserialize(sParams, List<String>.class);

 

-Hengky-

All Answers

Hengky IlawanHengky Ilawan

Hi SFDC_Learner,

 

Yes you can pass the list in the query string. You can use JSON serialize methods and pass the json string to the query string. Then on the next page, you just deserialize it back to the original data type.

 

List<String> params = new List<String>{'cityvalue','locationVal'};
String sParams = System.JSON.serialize(params);

List<String> dParams = (List<String>)System.JSON.deserialize(sParams, List<String>.class);

 

-Hengky-

This was selected as the best answer
SFDC_LearnerSFDC_Learner

Thanks. this is very good sample.

How can we pass the same through script??