Category: dev 501


Maps are very powerful application to visualise information. In today’s world, map plays a very important role as many customers want to integrate maps with their applications to represent their account, contact, lead and many more information visually through map.In one of my recent project, I came across a similar requirement where I need to integrate map with Visualforce to show lead information visually in map. To implement this requirement, I have chosen Mapbox. I know you have the question in mind – Why Mapbox, why not Google Map? The reason why I have chosen Mapbox, not the Google Map – I will come to it later. But for the time being let’s keep our focus completely on Mapbox.In this post, I will explain how you can integrate Mapbox with Visualforce page. I will start with a very basic example and then dig into more and more complex ones. I believe in this way, you will also feel more comfortable with Mapbox+Visualforce integration.Note – The day I am writing this post, the version of Mapbox API is: Version 2.2.1.Step 1 – Create Mapbox accountFirst you need to create a Mapbox account. You can do that by clicking on Signup button.Step 2 – Get Default Public Token Once you have logged in, go to your profile, followed by click on Apps to get your default public token. Below is the screenshot...

Read More


Today in this post, I will explain about “Dynamic VisualForce Bindings”. This was introduced in Spring’11 release and it allows developer to choose the list of fields to be displayed at run time, rather than at compile time. As a result, developer can write generic VisualForce pages which will display information about records without necessarily knowing the list of fields.Dynamic VisualForce Binding is supported for both standard and custom objects. The general form isreference[expression]where -reference – It can be either an sObject, or an Apex Class, or a global variable.expression – It evaluates to a String that is the name of a field, or a related object. In case of related object, it can be used recursively to select another related object or field.Important point – Dynamic VisualForce Page should always use a standard controller for the object and then implement any further customization through controller extensions.The below example will show how dynamic visualforce binding can be implemented to display list of fields from Account object at run time.Controller – ShowDynamicAccountFieldController 1 2 3 4 5 6 7 8 910111213141516171819202122232425262728293031323334353637383940414243444546474849public with sharing class ShowDynamicAccountFieldController { public ShowDynamicAccountFieldController(ApexPages.StandardController controller){ controller.addFields(dynamicFields); Account acc = (Account) controller.getRecord(); } public List<String> dynamicFields{ get{ if(dynamicFields == null){ dynamicFields = new List<String>(); dynamicFields.add(‘Name’); dynamicFields.add(‘AccountSource’); dynamicFields.add(‘NumberOfEmployees’); dynamicFields.add(‘Rating’); } return dynamicFields; } private set; } public void showFirstSet(){ checkAndInitiate(); dynamicFields.clear(); dynamicFields.add(‘Name’); dynamicFields.add(‘AccountSource’); } public void showSecondSet(){ checkAndInitiate();...

Read More

Implementing Decorator Design Pattern in Apex

This post is part of the series – Design Pattern in ApexI am sure as a developer, we all faced some situations where we need to have some kind of temporary fields just for calculation or displaying in the UI, but we don’t want to store that information in the database or more specific in object. To solve this type of problems, we have Decorator Design Pattern, which allows a user to add a new functionality to an existing object without modifying it’s internal structure. This pattern create a decorator class which wraps the original class and provides additional functionalities keeping class method signature same.Where I should use this design pattern?Below are few user cases, where we can use this design pattern -Say in a table, we are displaying a list of records and want to perform some operations on selected records. We can perform the same operation on each record, but from user interaction point of view, if we can provide some check-boxes so that user can select multiple records inside the table and perform the same operation on all the selected records. We can display check-box against each row, but that check-box information we will not store into the object level, these are only for Visual Force pages.Say when we are creating new accountss we are passing the same account information to some MDM (Master Data Management) system via integration. Once the...

Read More

Implementing Strategy Design Pattern in Apex

This post is part of the series – Design Pattern in ApexThe strategy design pattern is the one which allows an algorithm’s behavior to be chosen at run time. It is used to define a set of algorithms to solve a common problem. It allows unique logic per algorithm via encapsulations, but ensures that all algorithms are interchangeable at run time. Here the abstraction is achieved by an interface, whereas individual implementations are done at derived classes. So basically it looks like -Where I should use this design pattern?This design pattern should be used when you are planning to perform an operation that has a common end goal, but there can be different approaches/ways to achieve that goal. All these approaches can be chosen by client at run-time.Let me tell you few real-life Salesforce based example where this design pattern can be used -Let’s say in the account detail page, you want to display the current temperature of the city where the office located. Now based on the country/state, you may need to collect the temperature information from different websites, but your final goal is always the same i.e. showing the temperature.Let’s say you are calculating discounts per product based on month. Every month, the discount amount is getting calculated by different complex algorithms/formulas. Here also, your final goal is same i.e. calculating the discounts.Let’s say you want to set...

Read More

Implementing Singleton Design Pattern in Apex – Use Case III

This post is part of the series – Design Pattern in ApexToday in this post I will explain how Singleton Design Pattern can be used to call global describe only once.Requirement -When someone inserts an account record, you need to inspect all the fields in the account object.Implementation -Below is the trigger to start with -MyAccountTrigger-AccountHelper -The problem with this approach is that when someone enters huge number of accounts with dataloader, this code will work like -For each insert, it will create a new instance of AccountHelper which in turn will execute GlobalDescribe(). Very soon we will be hit by LimitException.To avoid that, we have to implement Singleton Design Pattern and below are the changes we need to do that -AccountHelper -MyAccountTrigger-Now you can see for a single transaction, we are calling GlobalDescribe only once because we are now not instantiating AccountHelper object for each Account insert, rather we are only instantiating one AccountHelper object per transaction.Hope you understood the usages of Singleton Design Pattern. If you have implemented this design pattern in any other situation, requesting you to share here. Thanks for your feedback....

Read More

Earlier Posts

  • 2024 (25)
  • 2023 (47)
  • 2022 (25)
  • 2021 (35)
  • 2020 (41)
  • 2019 (13)
  • 2018 (16)
  • 2017 (14)
  • 2016 (18)
  • 2015 (74)
  • 2014 (20)