Getting an error when tried to execute workbook apex code
"System.QueryException: List has no rows for assignment to SObject: Class.InvoiceUtilities.renumberLineItems: line 8, column 1 AnonymousBlock: line 1, column 1 AnonymousBlock: line 1, column 1"
public class InvoiceUtilities {
// class method to renumber Line Items for a given Invoice number
// returns a string that indicates success or failure
public static String renumberLineItems(String invoiceName) {
// create a copy of the target Invoice object and it's Line Items
Invoice__c invoice =
[Select i.Name, (Select Name From Line_items__r ORDER BY Name)
From Invoice__c i
Where i.Name = :invoiceName LIMIT 1];
// loop through each Line Item, renumbering as you go
Integer i = 1;
for (Line_item__c item : invoice.Line_items__r) {
item.Name = String.valueOf(i);
System.debug(item.Name);
i++;
}
// update the Line Items in one transaction, rollback if any problems
// and return error messages to the calling environment
try {
database.update(invoice.Line_items__r);
} catch (DmlException e) {
return e.getMessage();
}
// on success, return a message to the calling program
return 'Line items renumbered successfully.';
}
}