You need to sign in to do that
Don't have an account?

How to add select check box after displaying Lead and Contact records in visualforce page
Hi All,
How to add select check box after displaying Lead and Contact records in visualforce page.
I have written the apex class and visual force page for displaying records both leads and contacts here is my code..........
apex class:
public class objectcontroller
{
public List<selectOption> objects{get; set;}
public string selected{get; set;}
public List<contact> obj1{get; set;}
public list<lead> obj2{get; set;}
public boolean obj1Status{get; set;}
public boolean obj2Status{get; set;}
public objectcontroller()
{
obj1Status=false;
obj2Status=false;
objects= new List<selectOption>();
objects.add(new selectOption('contact','contact'));
objects.add(new selectOption('lead','lead'));
}
public pageReference getRecordofObject()
{
if(selected=='contact')
{
obj1=[select id,lastname,Email from contact limit 100];
obj1Status=true;
}
else
{
obj2=[select name,company,Status from lead limit 100];
obj2Status=true;
}
return null;
}
}
Visualforce page:
<apex:page controller="objectcontroller" showHeader="false">
<apex:form >
<apex:pageBlock title="Select a object">
<apex:selectList value="{!selected}" size="1">
<apex:selectOptions value="{!objects}"/>
</apex:selectList>
<apex:pageBlockButtons location="bottom">
<apex:commandButton action="{!getRecordofObject}" value="Show Records" rerender="cb"/>
</apex:pageBlockButtons>
</apex:pageBlock>
<apex:outputPanel >
<apex:pageBlock id="cb">
<apex:pageBlockSection >
<apex:pageBlockTable value="{!obj1}" var="ob1" rendered="{!obj1Status}">
<apex:column value="{!ob1.id}"/>
<apex:column value="{!ob1.lastname}"/>
<apex:column value="{!ob1.Email}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
<apex:pageBlockSection >
<apex:pageBlockTable value="{!obj2}" var="ob2" rendered="{!obj2Status}">
<apex:column value="{!ob2.id}"/>
<apex:column value="{!ob2.company}"/>
<apex:column value="{!ob2.status}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:outputPanel>
</apex:form>
</apex:page>
How to add select check box after displaying Lead and Contact records in visualforce page.
I have written the apex class and visual force page for displaying records both leads and contacts here is my code..........
apex class:
public class objectcontroller
{
public List<selectOption> objects{get; set;}
public string selected{get; set;}
public List<contact> obj1{get; set;}
public list<lead> obj2{get; set;}
public boolean obj1Status{get; set;}
public boolean obj2Status{get; set;}
public objectcontroller()
{
obj1Status=false;
obj2Status=false;
objects= new List<selectOption>();
objects.add(new selectOption('contact','contact'));
objects.add(new selectOption('lead','lead'));
}
public pageReference getRecordofObject()
{
if(selected=='contact')
{
obj1=[select id,lastname,Email from contact limit 100];
obj1Status=true;
}
else
{
obj2=[select name,company,Status from lead limit 100];
obj2Status=true;
}
return null;
}
}
Visualforce page:
<apex:page controller="objectcontroller" showHeader="false">
<apex:form >
<apex:pageBlock title="Select a object">
<apex:selectList value="{!selected}" size="1">
<apex:selectOptions value="{!objects}"/>
</apex:selectList>
<apex:pageBlockButtons location="bottom">
<apex:commandButton action="{!getRecordofObject}" value="Show Records" rerender="cb"/>
</apex:pageBlockButtons>
</apex:pageBlock>
<apex:outputPanel >
<apex:pageBlock id="cb">
<apex:pageBlockSection >
<apex:pageBlockTable value="{!obj1}" var="ob1" rendered="{!obj1Status}">
<apex:column value="{!ob1.id}"/>
<apex:column value="{!ob1.lastname}"/>
<apex:column value="{!ob1.Email}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
<apex:pageBlockSection >
<apex:pageBlockTable value="{!obj2}" var="ob2" rendered="{!obj2Status}">
<apex:column value="{!ob2.id}"/>
<apex:column value="{!ob2.company}"/>
<apex:column value="{!ob2.status}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:outputPanel>
</apex:form>
</apex:page>
Have to use wrapper class to add checkboxes while displaying records in vf page.I have made changes in your code.Modify according to your requirements. controller
Please refer below links which might help you further.
https://developer.salesforce.com/forums/?id=906F0000000DBmuIAG
http://www.sfdcpoint.com/salesforce/wrapper-class-in-apex/
Hope this helps you
If this helps kindly mark it as solved so that it may help others in future.
Thanks and Regards
All Answers
Have to use wrapper class to add checkboxes while displaying records in vf page.I have made changes in your code.Modify according to your requirements. controller
Please refer below links which might help you further.
https://developer.salesforce.com/forums/?id=906F0000000DBmuIAG
http://www.sfdcpoint.com/salesforce/wrapper-class-in-apex/
Hope this helps you
If this helps kindly mark it as solved so that it may help others in future.
Thanks and Regards
Thanks for the code and i have small modifications in the code can you help me with that......
Actually when i choose one object lead or contact only one object records should be displayed but two objects records are displaying can you help me with the requirment.......................
You just have to make other object pageBlockTable rendered attribute to false.
Try this one.
Hope this helps you
If this helps kindly mark it as solved so that it may help others in future.
Thanks and Regards
Thanks For your wonder full time actually in last conversation i forgot to mention one small requirment if you have time you can help me with that...
Actually i want to add Previous and Next buttons after dipalying the records..
Example if have 50 records first it will displayed only 10 records for next records we should have Next Or previous buttons...........
http://amitsalesforce.blogspot.com/search/label/Pagination
https://redpointcrm.com/add-pagination-to-your-visualforce-pages-using-the-soql-offset-clause
Hope this helps you
Thanks and Regards
Please refer the crmjetty site and salesforce blog which might you help the customization solustion for salesforce.
https://www.crmjetty.com/blog/salesforce/
https://www.crmjetty.com/salesforce-wordpress-customer-portal.htm