You need to sign in to do that
Don't have an account?
Usman Mushtaq 7
Create visual filters for Billing State/Province and Type in Visualforce
Hello Everyone,
I'm new to salesforce almost one month and I've been given an assignment which I'm unable to complete after many tries.
Task:
- Create a Visualforce Page that displays all of the records on the Account object, create a button next to each record displayed that will create a new contact record related to that specific account. (I've created a VF page that displays all the records of object Account and a button too but unable to implement the logic of the button that create new contact record related to that specific account. Visualforce Page: create a button next to each record displayed that will create a new contact record related to that specific account.)
- Create visual filters for Billing State/Province and Type (need complete help in this reagards)
I've created the filter but it is hard coded. Can someone look into my code and help in improving this. You help will be really much appreciated. Thanks
Controller:
public with sharing class ContactPageController {
public string filtercriteria{get; set;}
public string filtercriteria1{get; set;}
public list<Account> accountList{get; set;}
public void getAccounts() {
//accList = new list<Account>([SELECT Name, AccountNumber, Site, AccountType, BillingState FROM Account WHERE Billing State =: filtercriteria]);
accountList = new list<Account>([SELECT Name, Website, BillingState, Phone, Type FROM Account WHERE BillingState =: filtercriteria AND Type =: filtercriteria1]);
}
}
VisualForce:
<apex:page controller="ContactPageController" tabStyle="Account">
<apex:form >
<apex:pageBlock title="Accounts">
<apex:pageBlockSection title="Account Filter by Billing State/Province and Type" columns="1">
Select Billing State/Province:
<apex:selectList size="1" value="{!filtercriteria}">
<apex:actionSupport event="onchange" action="{!getAccounts}" rerender="table1"/>
<apex:selectOption itemLabel="" itemValue="" ></apex:selectOption>
<apex:selectOption itemLabel="NC" itemValue="NC" ></apex:selectOption>
<apex:selectOption itemLabel="KS" itemValue="KS" ></apex:selectOption>
<apex:selectOption itemLabel="TX" itemValue="TX" ></apex:selectOption>
<apex:selectOption itemLabel="OR" itemValue="OR" ></apex:selectOption>
<apex:selectOption itemLabel="CA" itemValue="CA" ></apex:selectOption>
<apex:selectOption itemLabel="IL" itemValue="IL" ></apex:selectOption>
<apex:selectOption itemLabel="NY" itemValue="NY" ></apex:selectOption>
<apex:selectOption itemLabel="Singapore" itemValue="Singapore" ></apex:selectOption>
<apex:selectOption itemLabel="AZ" itemValue="AZ" ></apex:selectOption>
</apex:selectList>
Select Type:
<apex:selectList size="1" value="{!filtercriteria1}">
<apex:actionSupport event="onchange" action="{!getAccounts}" rerender="table1"/>
<apex:selectOption itemLabel="" itemValue="" ></apex:selectOption>
<apex:selectOption itemLabel="Customer - Direct" itemValue="Customer - Direct" ></apex:selectOption>
<apex:selectOption itemLabel="Customer - Channel" itemValue="Customer - Channel" ></apex:selectOption>
</apex:selectList>
<apex:pageBlockTable id="table1" value="{!accountList}" var="l" columnsWidth="60%, 20%, 20%">
//columnsWidth="400px, 100px, 400px, 200px, 200px, 50px"
<apex:column >
<apex:facet name="header">Name</apex:facet>
<apex:outputLink value="/{!l.Id}" target="_blank">
<apex:outputField value="{!l.Name}"/>
</apex:outputLink>
</apex:column>
<apex:column value="{!l.BillingState}" />
<apex:column value="{!l.Type}" />
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>