function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Pankaj KPankaj K 

URGENT!!{ System.QueryException: List has no rows for assignment to SObject }

if(trigger.isUpdate)
        {
            for(Lead_Contact_MDO_Mapping__c lcMap:trigger.new)
            {
                if(lcMap.Lead_Name__c != null)
                {
                    listMdoLead.add(lcMap);
                    mapLead.put(lcMap.Id, [select Id, PRG_Deduction_Amount__c, MDO_Price__c from Lead where Id =: lcMap.Lead_Name__c limit 1 ]);
                }
                if(lcMap.Contact_Name__c != null)
                {
                    listMdoContact.add(lcMap);
                    mapContact.put(lcMap.Id, [select Id, Total_MDO_Amount__c from Contact where Id =: lcMap.Contact_Name__c limit 1]);
                }
                mapMDO.put(lcMap.Id, [select Id, Quantity_In_Hand__c, MDO_Price__c, Unit_Assigned__c from MDO_Detail__c where Id =: lcMap.MDO_Name__c limit 1]);
            }

 

When I am trying to upload the trigger it is showing error that System.QueryException: List has no rows for assignment to SObject cause by this line

 

mapMDO.put(lcMap.Id, [select Id, Quantity_In_Hand__c, MDO_Price__c, Unit_Assigned__c from MDO_Detail__c where Id =: lcMap.MDO_Name__c limit 1]);

 

Can somebody tell me why am i getting this error? and how to resolve it?

Thanks in advance.:)

raseshtcsraseshtcs

This means that the query [select Id, Quantity_In_Hand__c, MDO_Price__c, Unit_Assigned__c from MDO_Detail__c where Id =: lcMap.MDO_Name__c limit 1] is not returning any record. you need to modify the query so that it returns atleast one record.

Chamil MadusankaChamil Madusanka

Adding to previous reply, there are few other issues.

You have query in for loops

You have not bulkyfy your trigger

 

Refer following link to resolve above issues

 

http://wiki.developerforce.com/page/Apex_Code_Best_Practices

 

If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.