In my following AuraEnabled class, I am trying to clone the current record displayed in my lightning component page. This lightning component implements force:hasRecordId
and should insert it as new value instead of updating the current one.
But upon checking the developer console's debug logs, I always see this error:
System.QueryException: List has no rows for assignment to SObject
What should I do to fix said error?
ItemsController.cls
public with sharing class ItemsController {
@AuraEnabled
public static Item__c cloneItem(Id itemId){
Item__c itemToClone = new Item__c();
itemToClone = [SELECT Id, MasterField__c FROM Item__c WHERE Id =: itemId LIMIT 1];
Item__c newCloneItem = new Item__c();
newCloneItem = itemToClone.clone();
newCloneItem.MasterField__c = itemToClone.MasterField__c;
insert newCloneItem;
return newCloneItem;
}
}