You need to sign in to do that
Don't have an account?
roshmy salesforce
commandButton
Hi All,
I am new in salesforce world and trying to learn as much as I can. While playing around with VF page and Apex class controller I am stuck at one place. I am sharing the details here with code and scenario what I want to achieve. Hope I will get some help here -
Scenario : I want to create a button on VF page and once I click the button it should show me the records on my custom object in blocktable format.
I am able to do and see result thru SOQL and also when I am trying to display the data directly on the VF page ( without button) it showing fine. But I want when I click then only it should show the data n VF page.
Custom object Name : Employee__c
Apex Class code :-
public class EmployeeClass
{
public PageReference myemps() {
return null;
}
List <Employee__c> emp = [select Name,Salary__c,Skillset__c,Employee_ID__c from Employee__c ] ;
public List <Employee__c> getmyemps()
{
return (emp);
}
}
VF Page code :
<apex:page controller="EmployeeClass">
<apex:form >
<apex:pageBlock >
<apex:commandButton value="ListButton" action="{!myemps}" />
<apex:pageBlockSection >
<apex:pageBlockTable value="{!myemps}" var="i">
<apex:column value="{!i.Name}"/>
<apex:column value="{!i.Salary__c}"/>
<apex:column value="{!i.Skillset__c}"/>
<apex:column value="{!i.Employee_ID__c}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
I am new in salesforce world and trying to learn as much as I can. While playing around with VF page and Apex class controller I am stuck at one place. I am sharing the details here with code and scenario what I want to achieve. Hope I will get some help here -
Scenario : I want to create a button on VF page and once I click the button it should show me the records on my custom object in blocktable format.
I am able to do and see result thru SOQL and also when I am trying to display the data directly on the VF page ( without button) it showing fine. But I want when I click then only it should show the data n VF page.
Custom object Name : Employee__c
Apex Class code :-
public class EmployeeClass
{
public PageReference myemps() {
return null;
}
List <Employee__c> emp = [select Name,Salary__c,Skillset__c,Employee_ID__c from Employee__c ] ;
public List <Employee__c> getmyemps()
{
return (emp);
}
}
VF Page code :
<apex:page controller="EmployeeClass">
<apex:form >
<apex:pageBlock >
<apex:commandButton value="ListButton" action="{!myemps}" />
<apex:pageBlockSection >
<apex:pageBlockTable value="{!myemps}" var="i">
<apex:column value="{!i.Name}"/>
<apex:column value="{!i.Salary__c}"/>
<apex:column value="{!i.Skillset__c}"/>
<apex:column value="{!i.Employee_ID__c}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Use reRender attribute in apex command button and rendered attribute in pageblock Table
Below is the sample code for reference :
Controller:
Visualforce page :
Hope this will meet your requirement
If this helps you, Please Mark this answer as Best Answer.
Regards,
Sachin.