0

I am trying to update a checkbox field on a custom object when a checkbox is checked in a list of these objects. The error is saying that no rows have been returned by my query. I am getting the object based on the ID or Name of the record clicked. My problem is I don't know which to use. I have the Name field set as an autonumber.

<apex:pageBlockTable value="{!allNotes}" var="note" id="list">
            <apex:column value="{!note.Created__c}"/>
            <apex:column value="{!note.Body__c}"/>
            <apex:column> 
                <apex:inputCheckbox value="{!note.DidyaGetterDone__c}">
                    <apex:actionSupport event="onclick" reRender="list" action="{!checkNote}">
                        <apex:param assignTo="{!noteIdValue}" value="{!note.Name}"/>
                    </apex:actionSupport>
                </apex:inputCheckbox> 
            </apex:column>
        </apex:pageBlockTable>

Controller:

public with sharing class StudyPageController {

public Notes__c note{get;set;}
public List<Notes__c> allNotes{get;set;}
public String noteIdValue{get;set;}

public StudyPageController(){
    questionList = [Select id,body__c,answer__c,Name,Type__c,Explanation__c,Category__c,A__c,B__c,C__c,D__c,E__c,pic1__c,pic2__c,pic3__c,pic4__c,pic5__c From Question__c]; 
    allNotes = [Select Name,Created__c,body__c,DidyaGetterDone__c From Notes__c];
    note = new Notes__c();
}

 public void checkNote(){
  Notes__c updateNote = [Select ID,Name,DidyaGetterDone__c From Notes__c Where Name = :noteIdValue];
  updateNote.DidyaGetterDone__c = !updateNote.DidyaGetterDone__c;
  update updateNote;
  }
}

This is the error:

List has no rows for assignment to SObject Error is in expression '{!checkNote}' in page notespage: Class.StudyPageController.checkNote: line 67, column 1

  • you should prefer the id, best practice.. if it does not work with Id either, your param seems not to get passed to your controller. – Basti Nov 11 '17 at 18:52
  • When param gets passed it is passed as a key value pair, as far as i know you may have to put in a name attribute where name="noteIdValue". Give it a try by adding name to the apex:param and see if the value is passed to the controller – Rao Nov 11 '17 at 19:18
  • Good catch, both of you. I added the name attribute and it worked. – SallyRothroat Nov 11 '17 at 22:27
1

@madmax You have note as variable which is used as in apex:pageBlockTable and you also have the same variable name defined variable in controller. Please use different names. VF is considering the controller variable which has no value in name.

| improve this answer | |

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.