You need to sign in to do that
Don't have an account?
apexsutherland
Better way to convert !GETRECORDIDS output to quoted string for SOQL query
I am using the !GETRECORDIDS merge function to get record Ids from a related list and query SFDC for additional information before doing further processing. However, this is the only way that I could get the output of the !GETRECORDIDS function to be palatable for the WHERE IN part of my SOQL query:
Does anyone have a cleaner way to put the single quotes and commas in the string of Ids than the for loop that I wrote? I tried using the .toString() method, but it doesn't provide the single quotes around the Ids when it concatenates them with the rest of the SOQL query string.
Code:
idArray = {!GETRECORDIDS($ObjectType.Quoted_Asset__c )}; if (idArray[0] == null) { alert("Please select at least one row"); } else { var idString = ""; for (var i = 0; i < idArray.length; i++) { var idString = idString + "'" + idArray[i] + "'"; if(i<idArray.length-1){ var idString = idString + ","; } } alert(idString); var qaRecords = sforce.connection.query("Select Opportunity__c, Asset__c From Quoted_Asset__c Where Id in (" +idString+")");
Does anyone have a cleaner way to put the single quotes and commas in the string of Ids than the for loop that I wrote? I tried using the .toString() method, but it doesn't provide the single quotes around the Ids when it concatenates them with the rest of the SOQL query string.
There you go. Instant query generation for a list of values from a list view. And yes, it could probably be shorter, but I did want it to still be readable by the time I was done.
Generally, you only need to use query when you don't know the ID values, or you need data from related records, and you don't have their ID values.