You need to sign in to do that
Don't have an account?
AdamSBeal
Invalid Id from Querystring
I am passing some selected account Ids to my visualforce page in the querystring. I wish to add these to a related list in my visualforce page but I am getting an Invalid Id Error. I am wondering if it is because my id is type string. The strange thing is when I hard code this same Id value it works. Any ideas?
Here is the code:
String queryParamAccts = System.currentPagereference().getParameters().get('sAccts'); queryParamAccts = EncodingUtil.urlDecode(queryParamAccts, 'UTF-8'); List<String> orderAccounts = queryParamAccts.split(','); Set<Id> setAccountIds = new Set<Id>(); for(String s : orderAccounts) { setAccountIds.add(s); //error happens here }
Here is the debug log:
14:47:51.391 (391025000)|SYSTEM_METHOD_EXIT|[106]|System.debug(ANY) 14:47:51.391 (391095000)|SYSTEM_CONSTRUCTOR_ENTRY|[108]|<init>(Integer) 14:47:51.391 (391125000)|SYSTEM_CONSTRUCTOR_EXIT|[108]|<init>(Integer) 14:47:51.391 (391144000)|SYSTEM_METHOD_ENTRY|[109]|LIST<String>.iterator() 14:47:51.391 (391171000)|SYSTEM_METHOD_EXIT|[109]|LIST<String>.iterator() 14:47:51.391 (391184000)|SYSTEM_METHOD_ENTRY|[109]|system.ListIterator.hasNext() 14:47:51.391 (391199000)|SYSTEM_METHOD_EXIT|[109]|system.ListIterator.hasNext() 14:47:51.391 (391225000)|SYSTEM_METHOD_ENTRY|[111]|SET<Id>.add(Object) 14:47:51.391 (391287000)|EXCEPTION_THROWN|[EXTERNAL]|System.StringException: Invalid id: (001V000000606czIAA) 14:47:51.391 (391338000)|SYSTEM_METHOD_EXIT|[111]|SET<Id>.add(Object) 14:47:51.391 (391392000)|SYSTEM_METHOD_ENTRY|[132]|System.StringException.getMessage() 14:47:51.391 (391418000)|SYSTEM_METHOD_EXIT|[132]|System.StringException.getMessage() 14:47:51.391 (391487000)|SYSTEM_METHOD_ENTRY|[132]|ApexPages.addMessage(ApexPages.Message) 14:47:51.391 (391509000)|VF_PAGE_MESSAGE|The following error occurred attempting to save this order:Invalid id: (001V000000606czIAA)
Ok I figured this out. When I appended the account id's to the querystring from the previous page it added parenthesis before and after the accountid it for some reason "()". You can see it in the debug log but somehow I didn't notice it. I did this which fixed it:
setAccountIds.add(s.replace('(', '').replace(')', ''));
Still not quite sure how the parens are getting in there. Here is the code where I build the querystring:
pageReference page = new PageReference('/apex/TabbedOrder?sAccts=' + selectedAccounts);
selectedAccounts is a property which binds to a multi-select list