I have below VF page.I am passing value from data table.value="{!rlist.Id}" is coming as null.So on button click it is throwing me error for below soql as selectedresourceid =null

CKSW_BASE__Resource__c  res = [select id, name from CKSW_BASE__Resource__c  where id=:selectedresourceid limit 1 ];

Exact error:

System.QueryException: List has no rows for assignment to SObject
Error is in expression '{!rescheduleResource}' in component <apex:commandButton> in page assigntechssp: Class.AssignTechsSPCon.rescheduleResource:

VF page :

<apex:form >
   <apex:actionFunction name="go" action="{!getAllService}" rerender="list">
  <!--  <apex:outputpanel id="key">-->
    <apex:inputtext value="{!searchKey}" onkeyup="go();" id="heroes" html-autocomplete="off"/> 
 <!--    </apex:outputpanel> -->
     <apex:outputPanel id="list" >
        <apex:dataList value="{!serviceList}" var="s" style="width: 164px;overflow-y: hidden;z-index: 1; position : absolute;background-color: #edf2f1;">
          <apex:commandLink value="{!s.Name}"  >
          <apex:param value="{!s.name}" name="serviceId" assignTo="{!serviceId}"/>

     <apex:dataTable value="{!resourceList}" var="rlist" >
         <!--<apex:column ><apex:selectRadio value="{!rlist.name}">
                        <apex:selectOption value="{!rlist.name}" /> 
                    </apex:selectRadio></apex:column> -->
          <apex:column > <input type="radio" name="nametoselect" value="{!rlist.name}"/>&nbsp;{!rlist.name} &nbsp; {!rlist.Id}
          <apex:param name="selectedresourceid" value="{!rlist.Id}" assignTo="{!selectedresourceid}"/>


         <apex:outputText value="{!selectedresourceid}"/><br/>
         <apex:commandButton value="Reschedule resource" action="{!rescheduleResource}" />



public class AssignTechsSPCon {

    public List<CKSW_Base__Service__c> serviceList {get; set;}
    public List<CKSW_BASE__Resource__c> resourceList {get; set;}
    public String searchKey {get; set;}

     public String serviceId{
                serviceId= value ;
                searchKey =serviceId;
                System.debug('D : '+serviceId);
         public String selectedresourceid
            System.debug('D : '+selectedresourceid);
         public AssignTechsSPCon(){
        resourceList =  new List<CKSW_BASE__Resource__c>()  ; 
        resourceList = [select Id,name from CKSW_BASE__Resource__c ];

        System.debug('resourceList ::'+ resourceList);
        system.debug('selectedresourceid ::'+ selectedresourceid);


    public void getAllService(){

        string soql = 'SELECT Id, Name FROM CKSW_BASE__Service__c WHERE Name like\''+searchKey+'%\'' +' Limit 5';
        System.debug('SOQl ::'+ soql);

        serviceList = Database.query(soql);
        System.debug('serviceList :: '+ serviceList );
        System.debug('serviceId :: '+ serviceId);

     public void rescheduleResource(){
     System.debug('selectedresourceid  :: '+ selectedresourceid );
        CKSW_BASE__Service__c  soqlres = [select id, name, CKSW_BASE__Resource__c from CKSW_BASE__Service__c  where name=:serviceId limit 1 ]; 
        CKSW_BASE__Resource__c  res = [select id, name from CKSW_BASE__Resource__c  where id=:selectedresourceid limit 1 ];
        soqlres.CKSW_BASE__Resource__c = res.name;

        update soqlres;


The answer is simple, the tag <apex:param> can only be child of those elements :


you can check it in the official doc:

apex param doc


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.