You need to sign in to do that
Don't have an account?
Naveen 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.
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.
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
and when i make it then it showing this error unknown property string:status__c what to do...
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.
Comment out the whole code in vf page first then make the changes in apex class and then uncomment the code again.
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....
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 ?
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.
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