You need to sign in to do that
Don't have an account?
SFDC Guest
Display records in PageBlockTable with Radio buttons
Hi All,
I have created custom fields Credit_Card_Name__c, Credit_Card_Number__c in Contact object. And i have created one custom object - Credit_Card__c with fields Name, Card_Holder_Email__c, Credit_Card_Number__c.
I have created one custom button (name: Credit Card) on contact object of type (Display Type: Detail Page Button, Content Source: Visualforce Page).
I have inserted the records for Credit Card object.
When I click on custom button (name: Credit Card), I want to retrieve and display only those records which are related to Contact email in the form PageBlockTable with Radio buttons. After selecting one credit card, those details should be displayed in Contact object fields Credit_Card_Name__c, Credit_Card_Number__c. Please help to achieve this.
Below is the controller & vf page i tried.
public Class ContactCreditDetailsPage
{
public Contact con {get; set;}
public List<Credit_Card__c> ccard {get; set;}
public ContactCreditDetailsPage(ApexPages.StandardController stdCtr)
{
con = (Contact)stdCtr.getRecord();
con = [select id, email from contact limit 1];
}
public List<Credit_Card__c> getRecords()
{
ccard = new List<Credit_Card__c> ();
List<Credit_Card__c> results= [select Card_Holder_Email__c, Name, Credit_Card_Number__c from Credit_Card__c where Card_Holder_Email__c=: con.Email]; //where Card_Holder_Email__c=: con.Email
return results;
}
}
VF page:
<apex:page standardController="Contact" extensions="ContactCreditDetailsPage" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!Records}" var="cc">
<apex:column value="{!cc.Card_Holder_Email__c}"/>
<apex:column value="{!cc.Credit_Card_Number__c }"/>
<apex:column value="{!cc.Name}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Thanks
I have created custom fields Credit_Card_Name__c, Credit_Card_Number__c in Contact object. And i have created one custom object - Credit_Card__c with fields Name, Card_Holder_Email__c, Credit_Card_Number__c.
I have created one custom button (name: Credit Card) on contact object of type (Display Type: Detail Page Button, Content Source: Visualforce Page).
I have inserted the records for Credit Card object.
When I click on custom button (name: Credit Card), I want to retrieve and display only those records which are related to Contact email in the form PageBlockTable with Radio buttons. After selecting one credit card, those details should be displayed in Contact object fields Credit_Card_Name__c, Credit_Card_Number__c. Please help to achieve this.
Below is the controller & vf page i tried.
public Class ContactCreditDetailsPage
{
public Contact con {get; set;}
public List<Credit_Card__c> ccard {get; set;}
public ContactCreditDetailsPage(ApexPages.StandardController stdCtr)
{
con = (Contact)stdCtr.getRecord();
con = [select id, email from contact limit 1];
}
public List<Credit_Card__c> getRecords()
{
ccard = new List<Credit_Card__c> ();
List<Credit_Card__c> results= [select Card_Holder_Email__c, Name, Credit_Card_Number__c from Credit_Card__c where Card_Holder_Email__c=: con.Email]; //where Card_Holder_Email__c=: con.Email
return results;
}
}
VF page:
<apex:page standardController="Contact" extensions="ContactCreditDetailsPage" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!Records}" var="cc">
<apex:column value="{!cc.Card_Holder_Email__c}"/>
<apex:column value="{!cc.Credit_Card_Number__c }"/>
<apex:column value="{!cc.Name}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Thanks
I understood and I solved your problem.
see the code below: Please Mark as best Answer if this is helpful for you else tell me your problem.
All Answers
i read your problem bt i didn't understand your flow ....
but let me tell you if you want a checkbox with every record after Query then you have to work on Wrapper Classes
create your own wrapper class with that object and checkbox .
if you explain your problem then i can write your wrapper class
{
// declare your variables
//Wrapper class for your contact
public class WrapperClassForContact
{
public Contact con {get;set;}
public boolean checkbox{get;set;}
// declare your constructor of wrapper class
{
this.con=cc;
}
}
}
this is way how to declare wrapper class ....................read this link
https://developer.salesforce.com/page/Wrapper_Class
https://success.salesforce.com/answers?id=90630000000hSoLAAU
http://www.sfdcpoint.com/salesforce/wrapper-class-in-apex/
Please Mark as best Answer if this is helpful
thank you
Avaneesh Singh
I understood and I solved your problem.
see the code below: Please Mark as best Answer if this is helpful for you else tell me your problem.
I am getting below error after clicking on button "Add Card". After clicking on Add Card button, page should redirect to Contact page.
Visualforce Error
System.StringException: Invalid id: Gold Card
Error is in expression '{!m1}' in component <apex:commandButton> in page contactcreditdetailspage: Class.ContactCreditDetailsPage.m1: line 32, column 1
Class.ContactCreditDetailsPage.m1: line 32, column 1
as below
Radiobutton1 CreditCardName2 CreditCardNumber2
Radiobutton2 CreditCardName2 CreditCardName2
As I understood Sohel:
- you want to display all the card name from Credit_Card__c Object whose email is same as the contact on which Add Card button placed.
- After displaying the card name from Credit_Card__c Object, select any one card detail and fill these detainls in Contact object.
Sohel is it your problem ??If not then explain your problem correctly and what are the records you saved in your custom object.
Could you please make it redirect to Contact details page .
we can redirect very easily, check code below:
Please select as a best answer.
If your problem is solved.
Thanks Sohel.
Can we show how to display in pageBlockTable along with radio buttons using wrapper class.