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
Tall 642Tall 642 

System.QueryException: List has no rows for assignment to SObject on Milestone Autocomplete Code

I have implemented some code from developerforce to the auto-clomplete milestones, and in doing so I am getting the error in the Subject line. I'm not sure what is going wrong, here are the segments where tests are indicating being broken:

 

  Entitlement entl = [select id from Entitlement limit 1];
        String entlId;
        if (entl != null)
          entlId = entl.Id;

here is the link to the code that I am using. Any help would be appreciated:

 

http://wiki.developerforce.com/index.php/Case_Milestones_Utilities_Class

 

 

Best Answer chosen by Admin (Salesforce Developers) 
LakshmanLakshman

Modify line number 5 as:

 

List<CaseMilestone> cmsToUpdate = new List<CaseMilestone>();

cmsToUpdate = [select Id, completionDate from CaseMilestone cm where caseId in :caseIds and cm.MilestoneType.Name=:milestoneName and completionDate = null limit 1];

 

In short create instance of list first and then query.

 

Regards,

Lakshman

All Answers

LakshmanLakshman

Modify line number 5 as:

 

List<CaseMilestone> cmsToUpdate = new List<CaseMilestone>();

cmsToUpdate = [select Id, completionDate from CaseMilestone cm where caseId in :caseIds and cm.MilestoneType.Name=:milestoneName and completionDate = null limit 1];

 

In short create instance of list first and then query.

 

Regards,

Lakshman

This was selected as the best answer
ColinKenworthy2ColinKenworthy2

A SOQL Select statement returns a List of SObjects. Salesforce created this code shortcut to assign the result List to a single SObject. However it gives an error if the list is empty.

 

Assigning the Select results to a List of SObject does not give an error if the list is empty.

Tall 642Tall 642

Worked like a charm. Thank you. :smileyhappy: