You need to sign in to do that
Don't have an account?
satakshi
How to apply filter on city in the custom button
Hello,
I have created custom button on custom object. In this custom button i want to select records according to particular city. When i will selcet city "Mumbai" then i have to get all accounts having city mumbai. So that i can select some records from mumbai only. I have created code to display all the accounts records and to show selected some and its working fine. I want to know that how to apply filter so that i will get records according selected city.
Controller:
public with sharing class MyCompController1
{
public String str;
public MyCompController1(ApexPages.StandardController controller) {
str= ApexPages.currentPage().getParameters().get('id');
system.debug('**************Record id is**********************'+str);
if(wrapAccountList == null)
{
wrapAccountList = new List<wrapAccount>();
for(Account a: [select Id, Name, BillingCity from Account])
{
wrapAccountList.add(new wrapAccount(a));
system.debug('*****************wrapAccountList******************'+wrapAccountList);
}
}
}
public List<wrapAccount> wrapAccountList {get; set;}
public List<Account> selectedAccount{get;set;}
private List<Id> accountids=new list<Id>();
public List<Account> acc;
public PageReference processSelected()
{
selectedAccount = new List<Account>();
for(wrapAccount wrapAccountObj : wrapAccountList)
{
if(wrapAccountObj.selected == true)
{
selectedAccount.add(wrapAccountObj.acc);
//accWrap.acc.Name
system.debug('*****************!!!!!!!!!wrapAccountList******************'+selectedAccount);
}
}
/*for(Account acc: selectedAccounts)
{
Daily_Visit_Plan__c pv =new Daily_Visit_Plan__c();
pv.Name__c= acc.id;
insert pv;
} */
PageReference pageRef = new PageReference('/apex/Visitplan');
return pageRef;
}
public list<Account> srecs;
public list<Account> getSrecs()
{
srecs= [select Id, Name, BillingCity from Account];
system.debug('*****************!!!!!!!!!srecssrecssrecssrecs******************'+srecs);
return selectedAccount;
}
public class wrapAccount {
public Account acc {get; set;}
public Boolean selected {get; set;}
public wrapAccount(Account a)
{
acc = a;
selected = false;
}
}
}
VF PAGE1:
<apex:page standardController="Account" extensions="MyCompController1" standardStylesheets="false" sidebar="false">
<script type="text/javascript">
function selectAllCheckboxes(obj,receivedInputID)
{
var inputCheckBox = document.getElementsByTagName("input"); for(var i=0; i<inputCheckBox.length; i++)
{
if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1)
{
inputCheckBox[i].checked = obj.checked;
} } }
</script>
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="Create Visit" action="{!processSelected}" />
</apex:pageBlockButtons>
<apex:pageblockSection title="All Contacts" collapsible="false" columns="1">
<apex:pageBlockTable value="{!wrapAccountList}" var="accWrap" title="All Doctors And Chemists">
<apex:column >
<apex:facet name="header">
<apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/>
</apex:facet>
<apex:inputCheckbox value="{!accWrap.selected}" id="inputId"/>
</apex:column>
<apex:column value="{!accWrap.acc.Name}" />
<apex:column value="{!accWrap.acc.BillingCity}" />
</apex:pageBlockTable>
</apex:pageblockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
VF PAGE 2:
<apex:page standardController="Account" extensions="MyCompController1" sidebar="false">
<apex:pageBlock >
<apex:pageBlockSection title="Displaying selected records.." collapsible="false">
<apex:pageBlockTable value="{!srecs}" var="item" >
<apex:column value="{!item.id}"/> <apex:column value="{!item.name}"/>
<apex:column value="{!item.BillingCity}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>
I have created custom button on custom object. In this custom button i want to select records according to particular city. When i will selcet city "Mumbai" then i have to get all accounts having city mumbai. So that i can select some records from mumbai only. I have created code to display all the accounts records and to show selected some and its working fine. I want to know that how to apply filter so that i will get records according selected city.
Controller:
public with sharing class MyCompController1
{
public String str;
public MyCompController1(ApexPages.StandardController controller) {
str= ApexPages.currentPage().getParameters().get('id');
system.debug('**************Record id is**********************'+str);
if(wrapAccountList == null)
{
wrapAccountList = new List<wrapAccount>();
for(Account a: [select Id, Name, BillingCity from Account])
{
wrapAccountList.add(new wrapAccount(a));
system.debug('*****************wrapAccountList******************'+wrapAccountList);
}
}
}
public List<wrapAccount> wrapAccountList {get; set;}
public List<Account> selectedAccount{get;set;}
private List<Id> accountids=new list<Id>();
public List<Account> acc;
public PageReference processSelected()
{
selectedAccount = new List<Account>();
for(wrapAccount wrapAccountObj : wrapAccountList)
{
if(wrapAccountObj.selected == true)
{
selectedAccount.add(wrapAccountObj.acc);
//accWrap.acc.Name
system.debug('*****************!!!!!!!!!wrapAccountList******************'+selectedAccount);
}
}
/*for(Account acc: selectedAccounts)
{
Daily_Visit_Plan__c pv =new Daily_Visit_Plan__c();
pv.Name__c= acc.id;
insert pv;
} */
PageReference pageRef = new PageReference('/apex/Visitplan');
return pageRef;
}
public list<Account> srecs;
public list<Account> getSrecs()
{
srecs= [select Id, Name, BillingCity from Account];
system.debug('*****************!!!!!!!!!srecssrecssrecssrecs******************'+srecs);
return selectedAccount;
}
public class wrapAccount {
public Account acc {get; set;}
public Boolean selected {get; set;}
public wrapAccount(Account a)
{
acc = a;
selected = false;
}
}
}
VF PAGE1:
<apex:page standardController="Account" extensions="MyCompController1" standardStylesheets="false" sidebar="false">
<script type="text/javascript">
function selectAllCheckboxes(obj,receivedInputID)
{
var inputCheckBox = document.getElementsByTagName("input"); for(var i=0; i<inputCheckBox.length; i++)
{
if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1)
{
inputCheckBox[i].checked = obj.checked;
} } }
</script>
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="Create Visit" action="{!processSelected}" />
</apex:pageBlockButtons>
<apex:pageblockSection title="All Contacts" collapsible="false" columns="1">
<apex:pageBlockTable value="{!wrapAccountList}" var="accWrap" title="All Doctors And Chemists">
<apex:column >
<apex:facet name="header">
<apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/>
</apex:facet>
<apex:inputCheckbox value="{!accWrap.selected}" id="inputId"/>
</apex:column>
<apex:column value="{!accWrap.acc.Name}" />
<apex:column value="{!accWrap.acc.BillingCity}" />
</apex:pageBlockTable>
</apex:pageblockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
VF PAGE 2:
<apex:page standardController="Account" extensions="MyCompController1" sidebar="false">
<apex:pageBlock >
<apex:pageBlockSection title="Displaying selected records.." collapsible="false">
<apex:pageBlockTable value="{!srecs}" var="item" >
<apex:column value="{!item.id}"/> <apex:column value="{!item.name}"/>
<apex:column value="{!item.BillingCity}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>
if u have picklist of city, here i am taking picklist through code
try this:
Thanks
Ankur Saini
http://mirketa.com
All Answers
if u have picklist of city, here i am taking picklist through code
try this:
Thanks
Ankur Saini
http://mirketa.com
Its exactly what i want. You explain it very well. Your code is understandable. Thanks for the help.
Thanks & Best Regards,
Satakshi