You need to sign in to do that
Don't have an account?
Ertyq Mrsk
AuraEnabled Apex Class Returning Following Error: System.QueryException: List has no rows for assignment to SObject
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
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; } }
MyObject__c obj;
try{
obj = [SELECT id FROM MyObject__c WHERE name=:previouslyDefinedVar];
} catch(System.QueryException e){
// Perform logic here
}
For further reference, you can check this too,
https://stackoverflow.com/questions/48645338/list-has-no-rows-for-assignment-to-sobject-error-although-query-returns-rows
Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks.