You need to sign in to do that
Don't have an account?
SOQL WHERE Query using value from CSV file
I'm writing an Apex class that reads a CSV spreadsheet and inserts object records accordingly. I can confirm my program can read all the fields and create insert new records with the respective fields, but I'm having a problem when I try SOQL query an Object__c record using a value from the CSV file. I recieve an error telling me "caused by: System.QueryException: List has no rows for assignment to SObject".
So it's not finding the record when using the CSV value. However, when I hardcode the string into the SOQL query, it works.
String field = csvRow[4]); Object__c obj = [Select Id, Name from Object__c where Name =: field];
So it's not finding the record when using the CSV value. However, when I hardcode the string into the SOQL query, it works.
Object__c obj = [Select Id, Name from Object__c where Name = 'Test Object'];Please note that Object__c obj is a pre-existing object/record that exists prior to the execution of the Class so its existence is not dependent on any processes within the Class. Any assistance would be appreciated.
I think that after parse csv this value contains spaces, if it not help try to use system debug for determine actual value
Thanks,
Alex
All Answers
Error "caused by: System.QueryException: List has no rows for assignment to SObject". means that your query return nothing. You can query records to list and check list size.
Thanks,
Alex
I think that after parse csv this value contains spaces, if it not help try to use system debug for determine actual value
Thanks,
Alex