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
Ronan O'Neill 6Ronan O'Neill 6 

Is it possible to take the result of a database query as a String?

I was trying to build a URL using the address saved as a field in the database. 

I'm having trouble figuring out how to get the result of a database query as a string so as to edit and append it tio URL. 

Is there an easy way to do that?

Thanks.
Best Answer chosen by Ronan O'Neill 6
Sumitkumar_ShingaviSumitkumar_Shingavi
Hello Ronan,

I think you basically need to make a SOQL and get result in List/Map collection as per your need. After that, you can iterate on collection and form a parameter value as string and pass it on URL. Just like below:
 
//Form a String of comma separated Ids
List<Account> lAccounts = [SELECT Id, Name FROM Account LIMIT 10];
String strAccountIds = '';
for(Account accInstance : lAccounts) {
	strAccountIds += accInstance.Id;
	if(!String.isBlank(strAccountIds)) strAccountIds += ',';
}

//Form a PageReference
PageReference pref = Page.MyPage;
pref.getParameters().put('ids', strAccountIds);
return pref;

Thanks,
Sumit