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
NAGAM VENKATA KRISHNA 8NAGAM VENKATA KRISHNA 8 

requirement is when we select one value in the status picklist related records will display but get getting .But getting "List has no rows for assignment to SObject"

This is my code can any one help me to get out of this
apex code:-
public class defaultPicklistController {
public Lead lead {
get;
set;
}
public List < SelectOption> statusOptions {
get;
set;
}
// Constructor called on load.
public defaultpicklistController() {
lead = new Lead();
statusOptions = new List < SelectOption > ();
 
// Use DescribeFieldResult object.
Schema.DescribeFieldResult statusFieldDescription = Schema.Lead.Status.getDescribe();
// For each picklist value, a new select option created
for (Schema.Picklistentry picklistEntry: statusFieldDescription.getPicklistValues()) {
statusOptions.add(new SelectOption(pickListEntry.getValue(), pickListEntry.getLabel()));
// check default value and assign
if (picklistEntry.isDefaultValue()) {
lead.Status = picklistEntry.getValue();
}
}
}
     public void search(){
            lead = [select  Company,Name from lead where Status=:string.valueof(statusOptions)];
      }
}
vf page:-
<apex:page controller="defaultPicklistController">
<apex:form >
<b>Default value of Lead Status : </b>
    <apex:selectList size="1" value="{!lead.Status}">
        <apex:commandButton value="Search" action="{!search}" reRender="details"/>
<apex:selectOptions value="{!statusOptions}"/>
</apex:selectList>
    
    <apex:pageBlock>
        <apex:pageBlockTable value="{!lead}" var="slot" id="details">
             <apex:column value="{!slot.Name}"/> 
             <apex:column value="{!slot.company}"/> 
            </apex:pageBlockTable>
        </apex:pageBlock>
</apex:form>
</apex:page>
mukesh guptamukesh gupta
Hi NAGAM,

Your SQOL query not returning any record that's why you are facing this error.  First please debug in  your code and check SOQL return value.

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh