Tag Archives: SFDC

Radio Button in Visualforce Page

<apex:page >
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection >
                <apex:pageBlockSectionItem >Gender
                    <apex:selectRadio >
                        <apex:selectOption itemLabel="Male" itemValue="m"/>
                        <apex:selectOption itemLabel="Female" itemValue="f"/>           
                    </apex:selectRadio>     
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Salesforce Apex Design Patterns

  • Singleton: Minimizing object instantiation for improved performance and to mitigate impact of governor limits.
  • Strategy: Defining a family of algorithms, enscapsulating each one and making them interchangeable and selectable at runtime.
  • Decorator: Extending the functionality of an sObject in Apex.
  • Facade: Simplifying the execution of classes with complex interfaces (e.g. web service callouts).
  • Composite: Treating a group of objects in a similar manner to a single instance of that object.
  • Bulk State Transition: Efficiently tracking the change of a field value in a trigger and executing functionality based on this change.

Custom Label in Salesforce

Custom labels enable developers to create multilingual applications by automatically presenting information (for example, help text or error messages) in a user’s native language. Custom labels are custom text values that can be accessed from Apex classes, Visualforce pages, or Lightning components. The values can be translated into any language Salesforce supports.

We can create up to 5,000 custom labels for your organization, and they can be up to 1,000 characters in length.

Setup | App Setup | Custom Labels | Click ‘New Custom Label’ Button

Fill in the details and Click ‘Save’ button.

 

Custom Label in Visualforce page:
$Label.CustomLabel for Visualforce page.

<apex:page standardController="Account">
	
<h1>Example for Custom labels</h1>

	<apex:outputLabel value="{!$Label.Message}"/>
</apex:page>

 

Custom Label in Apex Class:
System.Label.Label_name for apex class

String msg = System.Label.Message; 

 

Custom Label in Lightning Component:
$Label.c.labelName for the default namespace.
$Label.namespace.labelName if your org has a namespace, or to access a label in a managed package.

<aura:component implements="flexipage:availableForAllPageTypes">
    
<div onclick="{!c.clickLabel}">
        <ui:outputText value="{!$Label.c.Message}" />
    </div>

</aura:component>

 

Custom Label in Javascript:
$A.get(“$Label.c.labelName”) for the default namespace.
$A.get(“$Label.namespace.labelName”) if your org has a namespace, or to access a label in a managed package.

({
    clickLabel : function(component, event, helper) {
        var label = $A.get("$Label.c.Message");
        alert(label);
    }
})

Summary field as footer of pageblock table in Visualforce page.

In this post I’ll show, how can we add the summary field or total amount or other information in footer of PageBlockTable or DataTable in Visualforce page.

In the below example I’m using the apex:facet name="footer" tag, to show sum of all the opportunity line items of an Opportunity in footer of PageBlockTable.

<apex:page standardController="Opportunity">    
    <apex:pageBlock title="{!Opportunity.Name}">    
        <apex:pageblocktable value="{!Opportunity.OpportunityLineItems}" var="item">
            <apex:column value="{!item.PricebookEntry.Name}"/>
            <apex:column value="{!item.ServiceDate}"/>
            <apex:column value="{!item.Quantity}"/>
            <apex:column value="{!item.UnitPrice}">
                <apex:facet name="footer">
                    <apex:outputText value="Total:" style="float: right;"/>
                </apex:facet>
            </apex:column>
            <apex:column value="{!item.TotalPrice}">
                <apex:facet name="footer">
                    ${!Opportunity.Amount}
                </apex:facet>
            </apex:column>
        </apex:pageblocktable>
    </apex:pageBlock>
</apex:page>