You need to sign in to do that
Don't have an account?
BritishBoyinDC
String Split Fail..
Not sure what I am missing here - this seems simple enough...
I have a MVP Picklist field called Languages__c. I want to split the field into a String List using ';' as the split. But when Languages has more than ten entries, ther debug shows me that the List contains the first ten, and then the characters ', ...)'
What I am missing here? What can I do to make sure all the values end up in the array?
public class cSearch{ Public String [] languagesvalue{get;set;} //This is the contructor method to build the search filters public cSearch(Contact con,Contact formatch){ //set search fields = values on contact being searched languagesvalue = new String [] {} ; if (con.Languages__c != null) { String [] sissues = con.Languages__c.split(';'); for (String s: sissues) { languagesvalue.add('\'' + s + '\''); } }
Looks like you are doing a query string type of DML. You might need to build the full query out with the value, referencing the array in that fashion may still be limiting the results returned. Maybe instead of building out your list as an array, build it out as the full text string, and then append it to the query string.
All Answers
Is it a multi select or just a picklist? If multi select the seperator is ";" not a ",".
Seems obvious... what does system.debug(con.languages__c) yield?
if you debug the contact field, it looks like you'd expect English, French,xxx etc...and includes all the values in the selected MVP.
But the converted string [] looks like this (English, French, xxx, ...)
So when it reaches the eleventh element, it decides not to add anymore, and instead, just adds ,...) to show there are more records to see but they weren't added....
Is there a parameter I am missing? I tried to add -1 etc but nothing seems to change the behavior?
I believe that is just the Debug function representation of the list. You could do a different type of test where you display the number of elements in the list using the size method to see if they are all present or not.
Ah, you're right - it does seem to have the right number of elements...so then the error is happening somewhere else...
The actual error is appearing here when I include that fields in a string for a SOQL query:
When cSearches.Languages has 10 elements, it works fine.
If I add an eleventh, I get this error:
And the debug on that string q shows the SOQL as being AND Languages__c INCLUDES ('English', 'French' 'xxx', ...) AND etc
That's why I thought it was the original split that was failing, but your suggestion seems to disprove that, so is the string to SOQL Query doing something odd?
Looks like you are doing a query string type of DML. You might need to build the full query out with the value, referencing the array in that fashion may still be limiting the results returned. Maybe instead of building out your list as an array, build it out as the full text string, and then append it to the query string.
Thanks Jim - that worked.