You need to sign in to do that
Don't have an account?
karol.freeberg
System.StringException: Invalid Id error in For loop.
I am getting the following error and I am at a loss on what is wrong. Can anyone please help? The line of code with the error is underlined below.
11:00:01.063 (63040986)|USER_DEBUG|[23]|DEBUG|---------------------------------rows 3
11:00:01.063 (63047571)|SYSTEM_METHOD_EXIT|[23]|System.debug(ANY)
11:00:01.063 (63058551)|SYSTEM_METHOD_ENTRY|[26]|LIST<User>.iterator()
11:00:01.063 (63228660)|SYSTEM_METHOD_EXIT|[26]|LIST<User>.iterator()
11:00:01.063 (63259893)|SYSTEM_METHOD_ENTRY|[26]|system.ListIterator.hasNext()
11:00:01.063 (63295436)|SYSTEM_METHOD_EXIT|[26]|system.ListIterator.hasNext()
11:00:01.063 (63545352)|FATAL_ERROR|System.StringException: Invalid id:
List<String> userAcctNames = new List <String>();
// Get all users modified in the last 3 days
User[] upusers = [Select ID, Department, Account_Name__c, contact_created__c,
LastModifiedDate From User Where LastModifiedDate >= :ckdt ];
system.debug('---------------------------------rows ' + upusers.size());
for (User theuser : upusers) {
// Collect the IDs
if (theuser.id != '') {
userids.add(theuser.id);
userAcctNames.add(theuser.Account_Name__c);
system.debug('--------------------------------added ' + theuser.id + theuser.account_name__c);
} //End if for collection of ids
} // end for loop
11:00:01.063 (63040986)|USER_DEBUG|[23]|DEBUG|---------------------------------rows 3
11:00:01.063 (63047571)|SYSTEM_METHOD_EXIT|[23]|System.debug(ANY)
11:00:01.063 (63058551)|SYSTEM_METHOD_ENTRY|[26]|LIST<User>.iterator()
11:00:01.063 (63228660)|SYSTEM_METHOD_EXIT|[26]|LIST<User>.iterator()
11:00:01.063 (63259893)|SYSTEM_METHOD_ENTRY|[26]|system.ListIterator.hasNext()
11:00:01.063 (63295436)|SYSTEM_METHOD_EXIT|[26]|system.ListIterator.hasNext()
11:00:01.063 (63545352)|FATAL_ERROR|System.StringException: Invalid id:
List<String> userAcctNames = new List <String>();
// Get all users modified in the last 3 days
User[] upusers = [Select ID, Department, Account_Name__c, contact_created__c,
LastModifiedDate From User Where LastModifiedDate >= :ckdt ];
system.debug('---------------------------------rows ' + upusers.size());
for (User theuser : upusers) {
// Collect the IDs
if (theuser.id != '') {
userids.add(theuser.id);
userAcctNames.add(theuser.Account_Name__c);
system.debug('--------------------------------added ' + theuser.id + theuser.account_name__c);
} //End if for collection of ids
} // end for loop
All Answers
And where are you adding this?
userids.add(theuser.id);