You need to sign in to do that
Don't have an account?
list has no rows for assignment to sobject
hi all,
i have a controller where in am getting this error displayed on my VF page.
Below is my code
in the above code,actually no record exisits in database to return the rows.But because of this error it discards the further execution of the code.
So can anyone please suggest how do i get rid of this error when there are no records present in database?
Thanks
i have a controller where in am getting this error displayed on my VF page.
Below is my code
public String distributionIds; public List<Distribution_List_Item__c> distItemLst{get;set;} //CONSTRUCTOR public VistAudit_VFC() { visitId=ApexPages.currentPage().getParameters().get('id'); relatedAccountId=ApexPages.currentPage().getParameters().get('accid'); distItemLst=new List<Distribution_List_Item__c>(); distributionIds=''; } //Constructs the data displayed on the page for all sections public void createData() { distributionIds=[select Id from Distribution_List__c where Business_Partner__c=:relatedAccountId AND Start_Date__c < today AND End_Date__c > today AND Status__c='Active'].Id; distItemLst=[select id from Distribution_List_Item__c where Distribution_List__c =:distributionIds]; }
in the above code,actually no record exisits in database to return the rows.But because of this error it discards the further execution of the code.
So can anyone please suggest how do i get rid of this error when there are no records present in database?
Thanks
The problem is you are gettting Distitmelist for that you need to use list of distribution id.
I hope this will helps you
Please mark this post as solved so that it benifit others.
Thanks
Karthick
All Answers
Change the type of the id variable..
like
Please mark this post as solved so that it benifit others.
Thanks
Karthick
your trick also doesnt work.. :(
Please mark this post as solved so that it benifit others.
Thanks
Karthick
You can just by pass it by puting a "Try catch"(In catch block dont put anything) block around the query. if you are sure if the future methods and this query are not related.
Regards,
Manjunath
Your second solution did wrok.But the scenario is that i want to use that of distribution list in multiple places.so
according to you solution,i'll have to apply the nested query every now and then.
So what is going wrong in my query?
cant i rectify it?just to save the several other nested queries as you just showed?
I too had thought of the same solution earlier,but then it doesn't seem to be a feasible solution.
Thanks for the reply
The problem is you are gettting Distitmelist for that you need to use list of distribution id.
I hope this will helps you
Please mark this post as solved so that it benifit others.
Thanks
Karthick