You need to sign in to do that
Don't have an account?
Ankit Kumar 169
Want to create a Vf page Which displays Accounts Name and related contact[Picklist]
Create a Vf page Which displays Accounts Name and related contact[Picklist] in a table format and Having a button in the last Column ""Delete"".It will delete the account and all the contacts related to the account."
All Answers
try this code for pick list
VF page:
<apex:page controller="AccountController1_picklistrendering">
<apex:form >
<apex:pageBlock title="Account Name">
Account Names
<apex:selectList value="{!selectedAccId}" size="1">
<apex:selectOptions value="{!AccountNames}"/>
<apex:actionSupport event="onchange" reRender="a"/>
</apex:selectList>
<br/><br/>
Related Contact Names
<apex:selectList value="{!selectedConId}" size="1" id="a">
<apex:selectOptions value="{!ContactNames}" />
</apex:selectList>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller:
public with sharing class AccountController1_picklistrendering {
public String selectedAccId{get;set;}
public String selectedConId{get;set;}
public List<SelectOption> getAccountNames() {
List<SelectOption> accOptions= new List<SelectOption>();
accOptions.add( new SelectOption('','--Select--'));
for( Account acc : [select Id,name from Account ] ) {
accOptions.add( new SelectOption(acc.Id,acc.name));
}
return accOptions;
}
public List<SelectOption> getContactNames() {
System.debug('Entered ContactNames account id...........'+selectedAccId );
List<SelectOption> conOptions= new List<SelectOption>();
List<SelectOption> options = new List<SelectOption>();
if(selectedAccId != null)
{
for( contact con : [select Id,name,accountid from contact where accountid=:selectedAccId ] ) {
conOptions.add( new SelectOption(con.Id,con.name));
}
}
else
{
conOptions.add( new SelectOption('--None--','--None--'));
}
return conOptions;
}
}
Hope so this helps you...!
Please mark this answer a Solution, if you found this answer as helpful.
I want the vf page like this,only particular contacts would be shown as related to particular Account.
In contact picklist it is shown all contacts. Please find the code below and resolve it .
Thnaks in Advance.
Controller :::
public class PickController {
public List<Account> accList {get;set;}
public String selectedAccId{get;set;}
public String selectedConId{get;set;}
public PickController(){
accList=[select Id,name,AccountNumber from Account];
}
public List<SelectOption> getContactNames() {
System.debug('Entered ContactNames account id...........'+accList);
List<SelectOption> conOptions= new List<SelectOption>();
List<SelectOption> options = new List<SelectOption>();
if(accList != null)
{
for( contact con : [select Id,name,accountid,account.name from contact where accountid=:accList ] ) {
conOptions.add( new SelectOption(con.Id,con.name));
}
}
else
{
conOptions.add( new SelectOption('--None--','--None--'));
}
return conOptions;
}
public PageReference delete1(){
return null;
}
}
VF Page ::
<apex:page controller="PickController">
<apex:form>
<apex:pageBlock title="Data Table">
<apex:dataTable value="{!accList}" var="a" styleClass="outBorder" width="1000px">
<apex:column styleClass="inBorder">
<apex:facet name="header">Account Name</apex:facet>
<apex:outputText >{!a.Name}</apex:outputText>
</apex:column>
<apex:column styleClass="inBorder" >
<apex:facet name="header">Contacts</apex:facet>
<apex:selectList value="{!selectedConId}" size="1" id="a">
<apex:selectOptions value="{!ContactNames}" />
</apex:selectList>
</apex:column>
<apex:column styleClass="inBorder">
<apex:facet name="header">Action Button</apex:facet>
<apex:commandButton value="Delete" action="{!delete1}"></apex:commandButton>
</apex:column>
</apex:dataTable>
</apex:pageBlock>
</apex:form>
</apex:page>
There are few things in my code that you need to add
1. Delete Function - I have just written a blank method.
2. Ensure that the user selects the check and clicks delete button
3. There is only one delete button in the page.
4. Page only displays that account, which has the contacts
Let me know if you need more help.
Thanks
Rajesh [ you can connect to me over linkedIn]
https://in.linkedin.com/in/rajesh-adiga-p-b3611ba7