You need to sign in to do that
Don't have an account?
Joe Brodar
Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, User: id value of incorrect type: 005U0000003GvJKIA0: [User__c]
I am attempting to match up users coming in from an external POST request to Salesforce users via a SOQL query of the name that returns a user record, then use the ID from the user record to insert a custom object record with a User Lookup field. However I am getting the following error:
Methods I have tried:
1. No string correction
2. Substring the usrId string to (0,15)
3. Take one character from the ID string of the user record at a time (0-14), and add to new usrId string
None of these have produced a working result. All three continue to return an 18 character string as the usrId variable. I have found several threads on this forum regarding this topic, but the only solutions that are listed with those questions are either syntax error with the specific code, or someone saying that you have to subString the ID. If anyone has any solutions or ideas beyond that, please let me know.
Thanks,
Joe
Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, User: id value of incorrect type: 005U0000003GvJKIA0: [User__c]This error is being thrown because the ID needs to be 15 characters, but is, in practice, coming out as 18 characters. I have tried a few different methods of limiting the string to 15 chars, but to no avail. This is frustrating because it works just fine in the sandbox environment, it is only when deployed to production that this error comes up.
Methods I have tried:
1. No string correction
// match names list to users and create records for each user finalCount = names.size(); for (Integer j = 0; j < finalCount; j++) { User matchUsr = [SELECT Id, Name FROM User WHERE Name = :names[j] LIMIT 1]; String usrId = matchUsr.Id; indivs.add(new Late_Tasks_by_User__c(User__c=usrId,Dependent_Tasks__c=deps[j],Actual_Late_Tasks__c=lates[j],Date__c=datej)); usrId = ''; echoOut += names[j] + ', '; }
2. Substring the usrId string to (0,15)
// match names list to users and create records for each user finalCount = names.size(); for (Integer j = 0; j < finalCount; j++) { User matchUsr = [SELECT Id, Name FROM User WHERE Name = :names[j] LIMIT 1]; String userMatch = matchUsr.Id; String usrId = userMatch.subString(0, 15); indivs.add(new Late_Tasks_by_User__c(User__c=usrId,Dependent_Tasks__c=deps[j],Actual_Late_Tasks__c=lates[j],Date__c=datej)); usrId = ''; echoOut += names[j] + ', '; }
3. Take one character from the ID string of the user record at a time (0-14), and add to new usrId string
// match names list to users and create records for each user finalCount = names.size(); for (Integer j = 0; j < finalCount; j++) { User matchUsr = [SELECT Id, Name FROM User WHERE Name = :names[j] LIMIT 1]; String userMatch = matchUsr.Id; String usrId = ''; for (Integer xc = 0; xc < 15; xc++) { usrId += userMatch.subString(xc, xc+1); } indivs.add(new Late_Tasks_by_User__c(User__c=usrId,Dependent_Tasks__c=deps[j],Actual_Late_Tasks__c=lates[j],Date__c=datej)); usrId = ''; echoOut += names[j] + ', '; }
None of these have produced a working result. All three continue to return an 18 character string as the usrId variable. I have found several threads on this forum regarding this topic, but the only solutions that are listed with those questions are either syntax error with the specific code, or someone saying that you have to subString the ID. If anyone has any solutions or ideas beyond that, please let me know.
Thanks,
Joe
In your case (no pun intended), the error is more likely because, at line 15, your User__c field is a lookup to some object other than a User. If you try to put a User Id into a field that looks up to some other type of object, you'll get a "id value of incorrect type" error.
"Why does it work in the sandbox, but not in Production?" you ask. Probably because the User__c field does look up to a User in the sandbox, but it's defined differently in Production.
All Answers
In your case (no pun intended), the error is more likely because, at line 15, your User__c field is a lookup to some object other than a User. If you try to put a User Id into a field that looks up to some other type of object, you'll get a "id value of incorrect type" error.
"Why does it work in the sandbox, but not in Production?" you ask. Probably because the User__c field does look up to a User in the sandbox, but it's defined differently in Production.
Thank you for your reply!