You need to sign in to do that
Don't have an account?
PC
Soql query is showing that list has no rows for assignment
Hi,
I have a custom object calle OLI__c
I m trying to fetch the order line items from OLI__c that are repeated against a particular customer in the Order__c Object.
But I am getting the error
List has no rows for assignment to SObject
An unexpected error has occurred. Your development organization has been notified.
I have tested the soql query in developer console and it is giving the desired result.
I have a custom object calle OLI__c
I m trying to fetch the order line items from OLI__c that are repeated against a particular customer in the Order__c Object.
But I am getting the error
List has no rows for assignment to SObject
An unexpected error has occurred. Your development organization has been notified.
I have tested the soql query in developer console and it is giving the desired result.
favourites = [select Menu__r.id menuid from OLI__c where Order__c in(SELECT id FROM Order__c where Customer__c=:c.id and Status__c='Completed') group By Order__r.Customer__r.name,Menu__r.Dish_Name__c,Menu__r.id having count(id)>1 ]; for(AggregateResult ar : favourites){ mid = String.Valueof(ar.get('menuid')); } if(mid!='') favmenu = [select id, name,Category__c,Description__c,Image__c,ImageURL__c,Dish_Name__c,Price__c, Special_Dish__c,Status__c,SubCategory__c,veg_non_veg__c,remarks__c from Menu__c where id=:mid];
favourites = [select Menu__r.id menuid from OLI__c where Order__c in(SELECT id FROM Order__c where Customer__c=:c.id and Status__c='Completed') group By Order__r.Customer__r.name,Menu__r.Dish_Name__c,Menu__r.id having count(id)>1 ];
List<String> menuIdList = new List<String>();
for(AggregateResult ar : favourites){
menuIdList.add(String.Valueof(ar.get('menuid')));
}
if(menuIdList!=null && !menuIdList.isEmpty())
favmenu = [select id, name,Category__c,Description__c,Image__c,ImageURL__c,Dish_Name__c,Price__c,
Special_Dish__c,Status__c,SubCategory__c,veg_non_veg__c,remarks__c from Menu__c where id IN : menuIdList];
All Answers
- The error "List has no rows for assignment to SObject" occurs when a query doesn't return any rows.
- https://help.salesforce.com/articleView?id=000159853&type=1
Hope it will be helpful.- Please mark it as best answer if the information is informative.so that question is removed from an unanswered question and appear as a proper solution.
ThanksRahul Kumar
List<Menu__c > favmenu
I have made the change List<Menu__c > favmenu as suggested by you.
now i have noticed that when i am making the query as
Public Id mid {get;set;} // I think there is a problem in the declaration of mid....It is not able to hold a list of ids.
Public List<Menu__c> favmenu {get;set;}
// if(mid!='') //commenting this line and in the below query adding limit 1, I m able to fetch the desired info for first menu item
favmenu = [select id, name,Category__c,Description__c,Image__c,ImageURL__c,Dish_Name__c,Price__c, Special_Dish__c,Status__c,SubCategory__c,veg_non_veg__c,remarks__c from Menu__c where id=:mid limit 1];
CAN YOU PLEASE SUGGEST SOMETHING ON THIS.
favourites = [select Menu__r.id menuid from OLI__c where Order__c in(SELECT id FROM Order__c where Customer__c=:c.id and Status__c='Completed') group By Order__r.Customer__r.name,Menu__r.Dish_Name__c,Menu__r.id having count(id)>1 ];
List<String> menuIdList = new List<String>();
for(AggregateResult ar : favourites){
menuIdList.add(String.Valueof(ar.get('menuid')));
}
if(menuIdList!=null && !menuIdList.isEmpty())
favmenu = [select id, name,Category__c,Description__c,Image__c,ImageURL__c,Dish_Name__c,Price__c,
Special_Dish__c,Status__c,SubCategory__c,veg_non_veg__c,remarks__c from Menu__c where id IN : menuIdList];