+ Start a Discussion
bramhabramha 

SOQL as URL Parameter

Hi,

 

   I want to know if i could pass a dynamic SOQL string as a parameter in  url.

 

  String soql = 'Some generated soQL Query' ;

 

Public String getPageURL() {

 PageReference pr = Page.QUICKSEARCH;

 pr.getParameters().put('query' , soql);

 pr.getURL();

}

 

I want to know if this causes any problem with speacial characters. WIll this work in all cases? Has any one tried this? And is this a proper way(Can i send a query string as url param)?

 

 

Thanks

Bramha

sfdcfoxsfdcfox

This is generally not recommended because of the potential for abuse; you'll want to make sure the SOQL matches a certain pattern (e.g. it accesses a certain object, has filters, etc). That being said, if you wish to do so, it is possible. The parameter should be correctly URL encoded for you, and similarly decoded on the other end without any special effort on your part. Special characters (" ", "+", "&", and so on) will not pose a problem.

nickwick76nickwick76

Haven't tried it, but try using urlencode and urldecode.

 

targetString = EncodingUtil.URLENCODE(targetString,'UTF-8');

 

// Niklas