You need to sign in to do that
Don't have an account?
Arun Kumar 279
How To make picklist dependent based on lookup field
Hi, I have a custom object (SALES__C) with Custom field (ACCOUNT__C) lookup,Contact picklist,currency__C field.
i have to do like this-- when a Account Lookup is selected contact associated with that account populated in Contact picklist.
There is A ADDROW fuctionality also.
all my fuctionality work. But whe i add a Another Row ,Then the all picklist have the same value as for last lookup Account.
here is my VP:
<apex:page controller="page4Controller" showHeader="false" >
<script type="text/javascript">
function Callmefunc(id)
{
var type = document.getElementById(id).value;
chk(type);
}
</script>
<apex:form >
<apex:actionFunction name="chk" action="{!con}" reRender="hi">
<apex:param name="lk" value="" />
</apex:actionFunction>
<apex:pageBlock title="Sales Details">
<apex:pageBlockButtons >
<apex:commandButton value="Add Row" action="{!addrow}"/>
<apex:commandButton value="Generate Pdf" />
</apex:pageBlockButtons>
<apex:PAGEBlockTable value="{!test}" var="s1">
<apex:column headerValue="Last Name">
<apex:inputField value="{!s1.Name}"/>
</apex:column>
<apex:column headerValue="Account">
<apex:inputField value="{!s1.Account__c}" id="check" onchange="Callmefunc('{!$Component.check}_lkid');">
</apex:inputField>
</apex:column>
<apex:column headerValue="Contacts">
<apex:selectList multiselect="false" size="1" id="hi" >
<apex:selectOptions value="{!accNames}" >
</apex:selectOptions>
</apex:selectList>
</apex:column>
<apex:column headerValue="Currency">
<apex:inputField value="{!s1.Currency__c}"/>
</apex:column>
<apex:column >
<apex:commandButton value="Remove" action="{!del}" />
</apex:column>
</apex:pAGEBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
This Is CONTROLLER:
public class page4Controller{
public string lk{get;set;}
public String act{get;set;}
public List<selectoption> accNames{get;set;}
public List<Contact> accNamessdrfs{get; set;}
public string conid{get;set;}
public integer removepos{get;set;}
public list<sales__c> test{get;set;}
public PageReference con(){
act =System.currentPageReference().getParameters().get('lk');
system.debug('============='+act);
accNames= new List<selectOption>();
accNamessdrfs=new List<Contact>();
accNames.add(new selectOption('none','----None-----'));
accNamessdrfs=[select LastName from Contact WHERE AccountId=:act];
for(Contact acc : accNamessdrfs)
{
accNames.add(new selectOption(acc.Lastname,acc.Lastname));
}
return null;
}
public PageReference pdf() {
return null;
}
public String getRenderAs() {
return null;
}
public void del()
{
if(test.size()>0){
for(Integer i=0;i<test.size();i++){
if(test[i].id==conid){
removepos=i;
}
}
test.remove(removepos);
}
}
public PageReference addrow() {
test.add(new sales__c());
return null;
}
public page4Controller(){
test=new list<sales__c>{(new sales__c())};
}
}
i have to do like this-- when a Account Lookup is selected contact associated with that account populated in Contact picklist.
There is A ADDROW fuctionality also.
all my fuctionality work. But whe i add a Another Row ,Then the all picklist have the same value as for last lookup Account.
here is my VP:
<apex:page controller="page4Controller" showHeader="false" >
<script type="text/javascript">
function Callmefunc(id)
{
var type = document.getElementById(id).value;
chk(type);
}
</script>
<apex:form >
<apex:actionFunction name="chk" action="{!con}" reRender="hi">
<apex:param name="lk" value="" />
</apex:actionFunction>
<apex:pageBlock title="Sales Details">
<apex:pageBlockButtons >
<apex:commandButton value="Add Row" action="{!addrow}"/>
<apex:commandButton value="Generate Pdf" />
</apex:pageBlockButtons>
<apex:PAGEBlockTable value="{!test}" var="s1">
<apex:column headerValue="Last Name">
<apex:inputField value="{!s1.Name}"/>
</apex:column>
<apex:column headerValue="Account">
<apex:inputField value="{!s1.Account__c}" id="check" onchange="Callmefunc('{!$Component.check}_lkid');">
</apex:inputField>
</apex:column>
<apex:column headerValue="Contacts">
<apex:selectList multiselect="false" size="1" id="hi" >
<apex:selectOptions value="{!accNames}" >
</apex:selectOptions>
</apex:selectList>
</apex:column>
<apex:column headerValue="Currency">
<apex:inputField value="{!s1.Currency__c}"/>
</apex:column>
<apex:column >
<apex:commandButton value="Remove" action="{!del}" />
</apex:column>
</apex:pAGEBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
This Is CONTROLLER:
public class page4Controller{
public string lk{get;set;}
public String act{get;set;}
public List<selectoption> accNames{get;set;}
public List<Contact> accNamessdrfs{get; set;}
public string conid{get;set;}
public integer removepos{get;set;}
public list<sales__c> test{get;set;}
public PageReference con(){
act =System.currentPageReference().getParameters().get('lk');
system.debug('============='+act);
accNames= new List<selectOption>();
accNamessdrfs=new List<Contact>();
accNames.add(new selectOption('none','----None-----'));
accNamessdrfs=[select LastName from Contact WHERE AccountId=:act];
for(Contact acc : accNamessdrfs)
{
accNames.add(new selectOption(acc.Lastname,acc.Lastname));
}
return null;
}
public PageReference pdf() {
return null;
}
public String getRenderAs() {
return null;
}
public void del()
{
if(test.size()>0){
for(Integer i=0;i<test.size();i++){
if(test[i].id==conid){
removepos=i;
}
}
test.remove(removepos);
}
}
public PageReference addrow() {
test.add(new sales__c());
return null;
}
public page4Controller(){
test=new list<sales__c>{(new sales__c())};
}
}