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
Naveen MadaanNaveen Madaan 

unable to view records in visual force page

Hi plz go through my apex page code and class. I wants to view my field records on visual force page and wans to update a field Login__c.
but i am just getting a save button and nothing else. 
MY VF page code is :
<apex:page Controller="contr">
<apex:form >
 <apex:pageBlock title="Student Record">
  
      <apex:pageBlockButtons >
      <apex:commandButton value="Save" action="{!save}"/>
   </apex:pageBlockButtons>
      <apex:pageBlockTable value="{!empl}" var="emp">
         <apex:column value="{!emp.status__c}"/>
        
         <apex:column value="{!emp.Name_emp__c}"/>
         
         <apex:column headerValue="enter login">
         <apex:inputField value="{!emp.Login__c}"/>
      </apex:column>
    </apex:pageBlockTable>
</apex:pageBlock>
  
        </apex:form>

</apex:page>

My class contr is :
public class contr {

  public View_attend__c acc{get;set;}  
List<view_attend__c> mylist = new List<view_attend__c>();
 public view_attend__c getempl() {
   
    string st='';
    st = ApexPages.currentPage().getParameters().get('id');
    mylist = [SELECT Login__c,status__c,Name_emp__c FROM view_attend__c where Name_emp__c =:st];
    
 return acc;
}
 

    public PageReference save() {
        update acc;
        return null;
    }
}

How i can fix it and get the results.


 
Bhanu MaheshBhanu Mahesh
Hi Naveen,

Are u passing any Id parameter in the url while loading the page,
Because this statement
st = ApexPages.currentPage().getParameters().get('id');
expecting Id parameter from current page and using that Id to get the view_attend__c record

And also 
mylist = [SELECT Login__c,status__c,Name_emp__c FROM view_attend__c where Name_emp__c =:st];
This query may return you more than one record so limit it to 1
and return mylist[0];

Use constructor to get the parameter from url because if you get any ecxeption ayny time then you may lose url parameters and in get method you won' get the value for str.

 public string st='';
public contr(){
  st = ApexPages.currentPage().getParameters().get('id');
}

Regards,
Bhanu Mahesh
Himanshu ParasharHimanshu Parashar
Please try following code for class
 
public class contr {

 public View_attend__c acc{get;set;}  
 public List<view_attend__c> mylist{get;set;}

 public contr()
 {
     List<view_attend__c> mylist = new List<view_attend__c>();
    string st='';
    st = ApexPages.currentPage().getParameters().get('id');
    mylist = [SELECT Login__c,status__c,Name_emp__c FROM view_attend__c where      Name_emp__c =:st];

 }

    public PageReference save() {
        update mylist;
        return null;
    }
}

 
Naveen MadaanNaveen Madaan
Hi, when i am using it getting error of unknown method contr.getempl() if i make this method then what shoud i write in this .
and when i make it then  it showing this error unknown property string:status__c what to do...
Himanshu ParasharHimanshu Parashar
public class contr {

 public View_attend__c acc{get;set;}  
 public List<view_attend__c> empl{get;set;}

 public contr()
 {
     List<view_attend__c> empl= new List<view_attend__c>();
    string st='';
    st = ApexPages.currentPage().getParameters().get('id');
    empl= [SELECT Login__c,status__c,Name_emp__c FROM view_attend__c where      Name_emp__c =:st];

 }

    public PageReference save() {
        update empl;
        return null;
    }
}
Please try above code. I forgot that you are using different variable code on page.
Naveen MadaanNaveen Madaan
Hi Himanshu
Now Error is :
The method List<view_attend__c> getEmpl() is referenced by Visualforce Page (employee) in salesforce.com. Remove the usage and try again. at line 4 column 31.
Himanshu ParasharHimanshu Parashar
Hi Naveen,

Comment out the whole code in vf page first then make the changes in apex class and then uncomment the code again.
Naveen MadaanNaveen Madaan
Himanshu i did it but as before  only showing the  save button and enter log in header name .
i think there is some problem is select command , it could not identify the page id from where it will get the values. 
anything else that i can do....
Himanshu ParasharHimanshu Parashar
Hi Naveen,

there can be differnet reason which is not allowing you to see the records so lets check step by step

1. Make sure you have records in view_attend__c object.
2. Make usre you are passing correct id for this page.
3. Make sure this contains any value for records Name_emp__c

can you post a screenshot of view_attend__c object ?
Naveen MadaanNaveen Madaan
Hi Himanshu,

1.   I have records in this object.
2.   I don't know how to pass the id of page. I just copy it from internet.
3. Name_emp__c is a master-detail field and also having records.

Plz find the attached screenshot.






User-added image


 
Himanshu ParasharHimanshu Parashar
can you post screenshot of object schema that will make thing more easier.
Bhanu MaheshBhanu Mahesh
Hi Naveen,

Are u passing the Id parameter through url?

Suppose your page name is test
then your url should be
yoursalesforceinstance/ape/test?id= id of Name_emp__c
Then your controller the id of Name_emp__c from url and fethch the view_attend__c record which is related to Name_emp__c

Regards,
Bhanu Mahesh