Category Archives: Salesforce

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.

Product, Pricebook and PricebookEntry

Product:

  • Product object is a catalog of items or services that your organization sells.
  • A product may contain one or more different sets of prices (PriceBookEntry).
  • Products are represented by Standard Object – Product2.

Pricebook:

  • Pricebook object store a list of products and services that your organization sells.
  • Each organization has one standard price book that defines the standard or generic list price for each product or service.
  • An organization can have multiple custom price books that can be used for specialized purposes, such as a discount price book, price books for different channels or markets, price books for select accounts or opportunities, and so on.
  • For some organizations, the standard price book might be the only price needed, but if you need to set up further price books, you can reference the standard price book when setting up list prices in custom price books.
  • PriceBooks are represented by Standard Object – Pricebook2.

PricebookEntry:

  • PricebookEntry object is a product entry (an association between a Pricebook2 and Product2) in a pricebook.
  • This object allows products to be linked to standard price book or custom price book with a price for a given currency.
  • One price book entry is linked to only one product.
  • One price book entry can only appear in one pricebook.
  • One price book entry can be used in multiple line items. This also further creates flexibility for users to set their own prices.
  • PricebookEntry are represented by Standard Object – Pricebookentry

Data Model: PricebookEntry is the junction object between Product and Pricebook.

1 Star2 Stars3 Stars4 Stars5 Stars (6 votes, average: 5.00 out of 5)
Loading...

Displaying Static Resources Image in Lightning Component

To reference a specific resource in component markup, we can use $Resource.resourceName within an expression. resourceName is the Name of the static resource. In a managed packaged, the resource name must include the package namespace prefix, like $Resource.yourNamespace__resourceName.

Sample Code:

<aura:component>
    <!-- Stand-alone static resources image file-->
    <img src="{!$Resource.resourceName}"/>
    <!-- Stand-alone static resources image file with Namespace-->
    <img src="{!$Resource.yourNamespace__resourceName}"/>
    
    <!-- Asset from an archive static resource image file-->
    <img src="{!$Resource.resourceName + '/assets/images/logo.png'}"/>
    <!-- Asset from an archive static resource image file with Namespace-->
    <img src="{!$Resource.yourNamespace__resourceName + '/assets/images/logo.png'}"/>
</aura:component>

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);
    }
})