• sheema R 6
  • NEWBIE
  • 0 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
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". 
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.