Tuesday, December 6, 2016

Visualforce - Beyond Basics Series 5 - App agnostic widgets in sidebar

Is there a customization section common to all Apps ?

Yes. Salesforce provides sidebar for this purpose. This sidebar is nothing but a collection of standard & custom components. Standard components include Create New, Recent Items, Tags, Custom Links, Recycle Bin.


What is allowed inside a sidebar component ?

you can have one of the following types for a component,

  1.   Links
  2.   Image
  3.   HTML
  4.   Visualforce


How can we use visualforce ?

Most of the time one can use visualforce to build a sidebar component for one of 3 purposes,

  1.   Output Stats, Quotes, Reminders, Important messages etc
  2.   Input a value from user & take action in Apex
  3.   Set of links for Navigation


Where is the code ?

I have given code for illustrating all these use cases. To try this out,
  1) you need to create a new 'Custom Component' under Setup -> Home -> Home Page Components.
        - with 'visualforce' type, height 200px, narrow type
        - select the visualforce page (copy the code from below)
  2) Then, you need to add this new component into current Home Page Layout.
<apex:page controller="testcls5_06122016">
<apex:form>
<!-- Display Section (Output Area) -->
<apex:outputPanel layout="block">
Today's Quote - {!$Setup.TodaysQuote__c.Quote__c}
</apex:outputPanel>
<hr/><br/>
<!-- User Input Section (Input Area) -->
<apex:inputText value="{!searchStr}" html-placeholder="Type something to search in products"/>
<apex:commandButton value="Search" action="{!doSearch}" reRender="SearchResultArea"/>
<apex:outputPanel id="SearchResultArea">
<apex:outputText value="{!searchResult}"/>
</apex:outputPanel>
<hr/><br/>
<!-- Navigation Section (Redirection Area) -->
<apex:outputPanel layout="block">
<apex:outputText value="Menu" style="font-weight:bold;"/>
<apex:panelGrid columns="1">
<apex:outputLink value="https://www.google.com" target="_blank">
Google
</apex:outputLink>
<apex:outputLink value="https://www.wikipedia.com" target="_blank">
Wikipedia
</apex:outputLink>
</apex:panelGrid>
</apex:outputPanel>
</apex:form>
</apex:page>
view raw gistfile1.txt hosted with ❤ by GitHub
public class testcls5_06122016 {
public String searchStr {get; set;}
public String searchResult {get; set;}
public void doSearch() {
searchResult = '10 products found';
}
}
view raw gistfile1.txt hosted with ❤ by GitHub



No comments:

Post a Comment

Thanks for reading my blog !