VISUALFORCE Pages part-2

Ratings:
(4)
Views:1053
Banner-Img
  • Share this blog:

VISUALFORCE Pages part-2

Visualforce Senarion 7:

The following visualforce code will automatically prompts to the "My Contacts" once we click on Contacts tab. Override the following Visual force page with the Contacts tab

Visualforce Code:

<apex:pagetabStyle="Contact_Relationship__c" >
 <script type="text/javascript">
 window.onload = function() {
 parent.document.location.href = "/a07?fcf=00B900000031bax";
}
</script>
 </apex:page> ID of the “My Contacts” list view

Learn Salesforce Online-VISUALFORCE Pages part-2

Visualforce Senarion 8:

Create the visualforce page with the following code.

Note: EnablingSectionsonPicklistValues

Visualforce Code:

<apex:page standardController="Account" extensions="SelectPicklist"
 showHeader="true" sidebar="true">
 <apex:form >
 <apex:pageBlock title="Page Details">
 <apex:pageBlockSection >
 <apex:selectList label="Year of Passing" value="{!YearValue}" size="1"
 multiselect="false" >
 <apex:actionSupport event="onchange" action="{!Picklist}"/>
 <apex:actionStatus startText="Applying value........">
 </apex:actionStatus>
 <apex:selectOptions value="{!Yearlist}"/>
</apex:selectList>
 </apex:pageBlockSection>
 </apex:pageBlock>
 <apex:outputPanel id="pd" rendered="{!YearValue1}">
 <apex:pageBlock title="2010 Hiding Details">
 <apex:pageBlockSection >
 <apex:pageBlockSectionItem >
 <apex:outputLabel value="Account Name">
 </apex:outputLabel>
 <apex:inputField value="{!Account.Name}"/>
 </apex:pageBlockSectionItem>
 <apex:pageBlockSectionItem >
 <apex:outputLabel value="Account Industry">
 </apex:outputLabel>
 <apex:inputField value="{!Account.Industry}"/>
 </apex:pageBlockSectionItem>
 </apex:pageBlockSection>
 </apex:pageBlock>
 </apex:outputPanel>
 <apex:outputPanel rendered="{!YearValue2}">
 <apex:pageBlock title="2011 Hiding Details">
 <apex:pageBlockSection >
 <apex:pageBlockSectionItem >
 <apex:outputLabel value="Account Phone">
 </apex:outputLabel>
 <apex:inputField value="{!Account.Phone}"/>
 </apex:pageBlockSectionItem>
 <apex:pageBlockSectionItem >
 <apex:outputLabel value="Account Type">
 </apex:outputLabel>
 <apex:inputField value="{!Account.Type}"/>
 </apex:pageBlockSectionItem>
 <apex:pageBlockSectionItem >
 <apex:outputLabel value="Account Description">
 </apex:outputLabel>
 <apex:inputField value="{!Account.Description}"/>
 </apex:pageBlockSectionItem>
 <apex:pageBlockSectionItem >
 <apex:outputLabel value="Account Rating">
 </apex:outputLabel>
 <apex:inputField value="{!Account.Rating}"/>
 </apex:pageBlockSectionItem>
 </apex:pageBlockSection>
 </apex:pageBlock>
 </apex:outputPanel>
 </apex:form>
</apex:page>

Select Packlist class Code:

public class SelectPicklist {
 public SelectPicklist(ApexPages.StandardController controller) {
 }
 public String YearValue{set;get;}
 public Boolean YearValue1{set;get;}
 public Boolean YearValue2{set;get;}
 public List<SelectOption> getYearlist () {
 List<SelectOption> options = new List<SelectOption>();
 options.add(new SelectOption('','--None--'));
 options.add(new SelectOption('1','2010'));
 options.add(new SelectOption('2','2011'));
 return options;
 }
 public void Picklist(){
 if(YearValue=='1')
 YearValue1 = true;
 else
 YearValue2 = True;
 }
 }

Create the button called “Hiding Sections” and override “Enabling Sectionson Picklist Values” visualforce page

Aspired to become an Salesforce? Explore the post to discover the know-hows on Salesforce Online Training.

Button Creation:

Learn Salesforce Online-VISUALFORCE Pages part-2

Learn Salesforce Online-VISUALFORCE Pages part-2

Once we click on “Hiding Sections” button, it will prompt to the following window have the field called “Year of Passing”, and values are 2010 and 2011

Learn Salesforce Online-VISUALFORCE Pages part-2

Once we select 2010 from the above picklist, then “2010 Hiding Details” section will be populated automatically

Learn Salesforce Online-VISUALFORCE Pages part-2

Visualforce Scenario 9:

Create the Visualforce page with following code

<apex:page Controller="InterviewOne_controller" sidebar="false">
 <apex:form >
 <apex:sectionHeader title="Interview One" />
 <apex:pageBlock title="All Accounts" tabStyle="Interview_One__tab">
 <apex:pageBlockTable value="{!listAccounts}" var="a">
 <apex:column headerValue="Account Name" value="{!a.name}"/>
 <apex:column headerValue="Billing State/Province"
 value="{!a.BillingState}"/>
 <apex:column headerValue="Phone" value="{!a.Phone}"/>
 <apex:column headerValue="Website" value="{!a.Website}"/>
 </apex:pageBlockTable>
 </apex:pageBlock>
</apex:form>
 </apex:page>

Interview one_Controller class

public class InterviewOne_controller{
 public list<Account> listAccounts{get;set;}
 public InterviewOne_controller(){
 list<Account>=new list<Account>();
 listAccounts = [select name,BillingState ,phone,Website from Account];
 }
 }

Create the Visualforce tab called “ +6: “and override the above visualforce with this tab

Learn Salesforce Online-VISUALFORCE Pages part-2

Once we click on the “Interview One” tab, then all the accounts will be populated in a table format which are not clickable.

Learn Salesforce Online-VISUALFORCE Pages part-2

Visualforce Scenario 10:

Create the Visualforce page with following code

<apex:page controller="InterviewTwo_controller" sidebar="false">
 <apex:form >
 <apex:sectionHeader title="Interview Two" />
 <apex:pageBlock mode="edit">
 <apex:pageBlockSection title="Search" >
 <apex:inputText label="Search" value="{!searchString }"/>
 <apex:commandButton value="Search" action="{!displayAccounts}"/>
 </apex:pageBlockSection>
 <apex:pageBlockSection title="Results" rendered="{!showmsg==true}">
 <apex:pageMessages rendered="{!showmsg}" >
 </apex:pageMessages> <br/>
 <apex:pageBlockTable value="{!listAccounts}" var="a"
 headerClass="headerclass" >
 <apex:column headerValue="Account Name" value="{!a.name}"/>
 <apex:column headerValue="Billing State/Province"
 value="{!a.BillingState}"/>
 <apex:column headerValue="Phone" value="{!a.Phone}"/>
 <apex:column headerValue="Website" value="{!a.Website}"/>
</apex:pageBlockTable>
 </apex:pageBlockSection>
 <apex:pageBlockSection title="Results" rendered="{!showmsg==false}">
 <apex:pageBlockTable value="{!listAccounts}" var="a">
 <apex:column headerValue="Account Name" value="{!a.name}"/>
 <apex:column headerValue="Billing State/Province"
 value="{!a.BillingState}"/>
 <apex:column headerValue="Phone" value="{!a.Phone}"/>
 <apex:column headerValue="Website" value="{!a.Website}"/>
 </apex:pageBlockTable>
 </apex:pageBlockSection>
 </apex:pageBlock>
 </apex:form>
 </apex:page>

Interview two_Controller class

public class InterviewTwo_controller{
 public list<Account> listAccounts{get;set;}
 public string searchString {get;set;}
 public boolean showmsg{get;set;}
 public InterviewTwo_controller(){
 listAccounts=new list<Account>();
 showmsg=false;
 }
 public pagereference displayAccounts(){
 String AccountQuery = 'select id, name,BillingState,Phone,Website from Account';
 if(searchString != '' && searchString != null)
 AccountQuery = AccountQuery + ' where name LIKE \'%' + searchString+'%\' ';
 listAccounts=database.query(AccountQuery);
 if(listAccounts.size()>0 && listAccounts!=null)
 showmsg=false;
 else{
 ApexPages.Message errMsg = new ApexPages.Message(ApexPages.Severity.Warni
 ng,'No Accounts Found');
 ApexPages.addMessage(errMsg);
 showmsg=true;
 }
 return null;
 }

Create the Visualforce tab called “ +6 /6 “and override the above visualforce with this tab

Learn Salesforce Online Training

Click on the “Interview Two” tab

Learn Salesforce Online Training

Enter the string “Osmania” in Search box and click on the “Search” button, then all the accounts started with the Osmania will be automatically populated in the “Results” section

Learn Salesforce Online Training

Visualforce Scenario 11:

Create the Visualforce page with following code

VisualForce Code

<apex:page controller="showSelectdAccounts" sidebar="false">
 <apex:form >
 <apex:sectionHeader title="Interview Three"/>
 <apex:pageblock >
 <apex:pageblockButtons >
 <apex:outputPanel >
 <apex:CommandButton value="Show Selected Accounts" status="status"
 action="{!ShowSelected}" rerender="spblock" />
 </apex:outputPanel>
 <apex:actionStatus startText="Please Wait..." id="status" />
 </apex:pageblockButtons>
 <span ><b> All Accounts </b> </span>
 <span style="padding-left:550px;"><b> Selected Accounts </b></span>
 <apex:pageblockSection columns="2">
 <apex:pageblockTable value="{!lstWrapper}" var="Ewrap">
 <apex:Column headervalue="Selected">
 <apex:inputCheckbox value="{!Ewrap.selected}"/>
 </apex:Column>
 <apex:Column headervalue="Account Name">
 <apex:outputfield value="{!Ewrap.Acc.name}"/>
 </apex:Column>
 <apex:Column headervalue="Phone">
 <apex:outputfield value="{!Ewrap.Acc.phone}"/>
 </apex:Column>
 </apex:pageblockTable>
 <apex:pageblockTable value="{!selectedAcc}" var="EAcc" id="spblock" >
 <apex:Column headervalue="Account Name">
 <apex:outputfield value="{!EAcc.name}"/>
 </apex:Column>
 <apex:Column headervalue="Phone">
 <apex:outputfield value="{!EAcc.phone}"/>
 </apex:Column>
 </apex:pageblockTable>
 </apex:pageblockSection>
 </apex:pageblock>
 </apex:form>
 </apex:page>

Show Selected Accounts Class:

public with sharing class showSelectdAccounts {
 public list<Account> lstAcc{get;set;}
 public list<Account> selectedAcc{get;set;}
 public list<wrapper> lstWrapper{get;set;}
 public boolean noAcc{get;set;}
 public showSelectdAccounts(){
 lstWrapper = new list<Wrapper>();
 noAcc = false;
 lstAcc = [select id,name,phone from Account];
 wrapper objwrap;
 for(Account objA:lstAcc){
 objwrap = new Wrapper();
 objwrap.Acc = objA;
 lstWrapper.add(objwrap);
 }
 }
 public void ShowSelected(){
 selectedAcc = new list<Account>();
 selectedAcc.clear();
 for(Wrapper objWrap:lstWrapper){
 if(objWrap.selected){
 noAcc = true;
 selectedAcc.add(objWrap.Acc);
 }
 }
 if(!noAcc){
 system.debug('8888888'+noacc);
 ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'No
 Account Selected'));
 }
 }
 public class wrapper{
 public boolean selected{get;set;}
 public Account Acc{get;set;}
 }
 }

Create the Visualforce tab called “ +6/“and override the above visualforce with this tab

Learn Salesforce Online Training

Click on “Interview Three” tab

[gallery ids="3193"]

Check the checkbox in the selected column and click on “Show Selected Accounts” button, then those selected accounts will be automatically populated in the “Selected Accounts” section

64

Visualforce Scenario 12:

Create the Visualforce page with following code

Visual Force Code:

<apex:page controller="InterviewFourClass" sidebar="false">
 <apex:form >
 <apex:sectionHeader title="Interview Four"/>
 <apex:pageblock tabstyle="Contract" title="Accounts with Contacts">
 <apex:pagemessages />
 <apex:repeat value="{!lstAcc}" var="EAcc" >
 <apex:pageblockSection title="{!EAcc.name}" columns="1">
 <apex:pageblockTable value="{!EAcc.Contacts}" var="Econ"
 columnswidth="25%,25%,25%,25%">
 <apex:column headerValue="First Name">
 <apex:outputText value="{!Econ.firstname}" />
 </apex:Column>
 <apex:column headerValue="Last Name">
 <apex:outputText value="{!Econ.lastname}" />
 </apex:Column>
 <apex:column headerValue="Phone Name">
 <apex:outputText value="{!Econ.phone}" />
 </apex:Column>
 <apex:column headerValue="Email">
 <apex:outputText value="{!Econ.Email}" />
 </apex:Column>
 </apex:pageblockTable>
 </apex:pageblockSection>
 </apex:repeat>
 </apex:pageblock>
 </apex:form>
 </apex:page>

Interview FourClass:

public with sharing class InterviewFourClass {
 public list<Account> lstAcc{get;set;}
 public InterviewFourClass(){
 lstAcc = new list<Account>();
 lstAcc = [select id,name,(select id,lastname,phone,firstname,email from Contacts),p
 hone from Account];
 ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'this pa
 ge was created ONLY one Query'));
}
 }

Create the Visualforce tab called “ +6 “and override the above visualforce with this tab

Learn Salesforce Online Training

Click on “Interview Four” tab and which gives the list of accounts and all the contacts that are associated with that account.

Learn Salesforce Online Training

Visualforce Scenario 13:

Create the Visualforce page with following code

Visual Force Code:

<apex:page controller="InterviewFifthClass" sidebar="false" >
 <apex:form >
 <apex:pageBlock >
 <apex:pageMessages />
 <apex:sectionHeader title="Interview Five"/>
 <apex:pageBlock title="All Accounts">
 <apex:pageBlockTable value="{!lstacc}" var="l" >
 <apex:column headerValue="AccountName" >
 <apex:commandLink value="{!l.name}" action="{!click}"/>
 </apex:column>
 <apex:column headerValue="Billing State/Province"
 value="{!l.BillingState}">
 </apex:column>
 <apex:column headerValue="phone" value="{!l.phone}">
 </apex:column>
 <apex:column headerValue="website" value="{!l.website}">
 </apex:column>
 </apex:pageBlockTable>
 </apex:pageBlock>
 </apex:pageBlock>
 </apex:form>
 </apex:page>
 InterviewFifthClass Code:
 public with sharing class InterviewFifthClass {
 public pagereference click() {
 ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'you clic
 ked on Name...'));
 return null;
 }
 public InterviewFifthClass (){
 lstacc = [select id, name, BillingState,phone,website from account];
 ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Sele
 ct an Account by Clicking its Name.'));
 }
 public List<account> lstacc { get; set;
}
}

Create the Visualforce tab called “ +6 +“and override the above visualforce with this tab

Learn Salesforce Online

Once we click on the “Interview five” tab, then all the accounts will be populated in a table format which are we can clickable.

Learn Salesforce Online-VISUALFORCE Pages part-2

For in-depth understanding of Salesforce click on

You liked the article?

Like : 0

Vote for difficulty

Current difficulty (Avg): Medium

Recommended Courses

1/15

About Author
Authorlogo
Name
TekSlate
Author Bio

TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.


Stay Updated


Get stories of change makers and innovators from the startup ecosystem in your inbox