You need to sign in to do that
Don't have an account?

How to retrieve SOQL results as comma separated string?
Hello,
I am trying to extract a list of ids from a SOQL query as a comma separated string so that I can then pass the string to another method which will create a PDF of the records. The results should look like this: X2VV0000000DxXxxxx,X2VV0000000DxXxXXX,X2VV0000000XxXtXXX
Since result.getParameters().put() is expecting two strings, the Apex won't compile. I get: Save error: Incompatible value type LIST<Letter__c> for MAP<String,String>
Here is the code:
public PageReference generateBatchPDF() { String letterIDs = ApexPages.CurrentPage().getParameters().get('letterIDs'); System.Debug('DEBUG: String letterIDs = '+letterIDs); String[] listofids = letterIds.split(','); List<Letter__c> printletters = [select id from Letter__c where format__c != 'email only' and id IN :listofids]; System.Debug('DEBUG: List printletters = '+printletters); PageReference result=new PageReference('/apex/EOTLBatchPDF'); result.getParameters().put('id', printletters); return result; }
You may have wanted to do this, not sure:
String params = '';
for(integer x =0;x<printletters.size();x++){
if(x>0) params +=',';
params += printletters[x].id;
}
All Answers
just use:
or itenerate over the list if you are searching for a record to use
You may have wanted to do this, not sure:
String params = '';
for(integer x =0;x<printletters.size();x++){
if(x>0) params +=',';
params += printletters[x].id;
}
Thank you! That worked beautifully!