Lightning Data Service – Standard Controller for Lightning Components

Best Practices for Salesforce Lightning Component. How Lightning Data Service can improve Lightning Component performance and solve inconsistent data problem without writing single line of Apex code. Demo source code, image and slides included.

If you have worked on Visualforce and started playing with Lightning Component, you must have identified one important missing feature, which is standard Controller.

Lets assume a scenario, you have two Lightning Components on Account page. One Lightning Component is used to show some fields and other component is used to edit same record.

Problem 1 :

To achieve this, both Lightning components would invoke Apex method separately at the cost of performance, by issuing duplicate server calls. Below image depicts problem, where multiple Lightning component requests same content by making separate server calls.

Lightning Components - Duplicate Server Calls
Lightning Components – Duplicate Server Calls

Continue reading “Lightning Data Service – Standard Controller for Lightning Components”

Lookup component in Salesforce Lightning

Author posted by Jitendra on Posted on under category Categories Salesforce and tagged as Tags , with Leave a comment on Lookup component in Salesforce Lightning

Salesforce Lightning component in plain JavaScript and SLDS with complete source code

Salesforce comes up with many out of box UI components and Lightning Base components. However, one important component missing is Lookup component or Type ahead component in Lightning. There are some lookup components available however either they are using some JavaScript library or UI doesn’t match with Salesforce Lightning Design system. So, I wanted to have something similar used by Salesforce Lightning interface itself and come up with this component. Complete source code of this component can be found on my Github repository also.

Before, jumping directly to source code, lets first discuss some important points. Continue reading “Lookup component in Salesforce Lightning”

Use Hierarchy custom settings to avoid hard coding in formula field, custom button, process builder or workflow rules

Example of using Hierarchy custom settings in formula field, custom button, process builder and workflow rules. Youtube video included.

Avoiding hard coded Ids or values from formula field, custom button, process builder, Workflow rules or Approval process using Hierarchy custom setting is not something new. This idea exists from many years in Salesforce ecosystem. However, some times I have seen developers and admins debating on same question, so though to put a consolidated blog post on same.

Why you should avoid hard coded values or Ids in Salesforce ?

Answer is very simple, maintenance. When sandboxes are refreshed or metadata deployed to different instances, admins would need to change values manually. If we are talking about manual post deployment step, then we are also talking about nightmare of maintaining list of manual post build steps.

Can we use Custom Labels to avoid hard coded Ids / values in Salesforce ?

Technically yes, but I would suggest not to use custom labels in Salesforce to avoid hard coded Ids because of below Issues

  •  Dataloader does not support custom label bulk load / restore / export
  • Imagine there are 100’s of custom label and it needs to be different for each Salesforce instances. You would be left either with manual step or some external tool which may not be allowed / approved by customer.

Hierarchy Custom Settings to Rescue

If you are from Java / C#, consider Custom setting as resource file. Here, you would store information about your application which doesn’t change frequently and controls behavior of application. There are two types of custom settings

  • List Custom Setting
    • This custom setting is equivalent to custom / standard object. We can store values in tabular format.
  • Hierarchy Custom Settings
    • This custom setting can be used in formula field, process builder, custom button, Workflow rules or Approval process.
    • Most unique feature about Hierarchy custom setting is that we can have different values at Organization level, profile level and user level.
    • Custom setting can be used in formula fields using global variable $Setup. Syntax to use custom setting is
      
      {!$Setup.CustomSettingName__c.CustomFieldName__c}
      
      
    • Highest priority is given to value defined at user level then profile and at last organization level.

Continue reading “Use Hierarchy custom settings to avoid hard coding in formula field, custom button, process builder or workflow rules”

Show Lightning component on public website without authentication

How to show Lightning component on public sites without need of user authentication

I have posted few articles on Lightning OutIn this post, we will see how Lightning components can be displayed on public website. To access these Lightning components, users don’t need to login to Salesforce.

For this post, I will consider Text slider component created in this post. Using this same method, I have displayed Live demo of Lightning component on wordpress blog. Continue reading “Show Lightning component on public website without authentication”

Text Slider Lightning Component for Salesforce with Live Demo

How to use Nested Components and create a simple yet powerful Text Slider Component in Lightning for Salesforce

In this post we will create simple and powerful Text Slider Component in Lightning.

Below are list of all features supported by this Component

  • Its pure CSS based without any JavaScript libraries therefore super fast
  • Long contents are auto scrolled with nice overloaded CSS for scroll bars
  • Ability to set Header and Body Text for each slides
  • Enable or disable auto background colors
  • Enable or disable auto slideshow
  • Control slides delays in case timer enabled
  • If auto background color turned off then ability to control background and text color
  • Slider contents are un-escaped means we can render richtext content

Continue reading “Text Slider Lightning Component for Salesforce with Live Demo”

Design Continuation Server in Salesforce

How to implement Continuation Server in Salesforce with the help of Action Function and Continuation Object

Continuation Server using ActionFunction in Salesforce
Continuation Server using Action Function in Salesforce

If you are new to Continuation Object in Salesforce then would suggest to read introduction post first. In last post, we discussed how to implement limitless chaining of Continuation Object using JavaScript remoting. In this post, we would try to achieve same, but instead of using JavaScript remoting, we would be using ActionFunction.

Why do we need chaining of Continuation Object

  • From Apex, we can only chain 3 Continuation Object
  • If we call API synchronously, chances are very high that it will run for more than 5 sec and contributing towards Concurrent Apex limit
  • Getting CPU timelimit error is also high
  • Making synchronous call also means risking scalability of Salesforce instance
  • You don’t want user to wait till call out completed, let them work and update user interface once response is received

Continue reading “Design Continuation Server in Salesforce”

Limitless Chaining of Continuation object in Salesforce

How to create a Continuation Server in Salesforce with the help of JavaScript remoting and Continuation Object

Chaining of Continuation Object in Salesforce
Chaining of Continuation Object in Salesforce

Around two years back, I posted an article on Continuation Object in Salesforce. As we know because of governor limits like concurrent Apex limit or CPU time limit errors, its always recommended to perform long running Apex process asynchronously. Processes specially like calling external API.

We can come up with multiple designs if number of APIs are less. However, you would risk scalability of Salesforce if number of APIs to be called is 10+. We cannot use chaining of continuation object directly as currently its limited to 3. If we call these API’s from Javascript (like using JavaScript remoting) then still we are using synchronous Apex which would be trade off for scalability.

What happens when we try to chain more than 3 Continuation Object call
What happens when we try to chain more than 3 Continuation Object in Salesforce

In Short, below are challenges in front of us

  • We need to call 10+ API from Visualforce
  • Cannot use chaining of Continuation Object as current chaining limit is 3
  • Cannot invoke each API from JavaScript remoting because it will be considered as Synchronous Apex

Continue reading “Limitless Chaining of Continuation object in Salesforce”

Getting started with Salesforce DX – Salesforce Developer Experience

Introduction and basics of Salesforce Developer Experience (Salesforce DX) with source code and Video tutorials

Important : At time of writing this post, Salesforce DX is in pilot phase. Mostly any product in Salesforce goes from Pilot to Beta and then Generally available. There is no guarantee that if this product is released, it would work like exactly same as written in this post.

If we already have Salesforce Metadata API, Force.com IDE and other tools then why do we need one more tool like Salesforce DX ?

In tools like Changeset, Metadata API or Force.com IDE, source of truth is Sandbox. Although we can setup process and continuous integration (CI) to use some source code management (SCM) like Git or SVN. However these kind of setup takes time, expertise and lot of effort.

Salesforce DX not only solves above problem but

  • Ability to consider SCM as source of truth
  • Use any favorite IDE or any SCM
  • Powerful CLI to help minimizing complexity of setting up CI
  • Updated Force.com IDE to support Salesforce DX if you are not comfortable with CLI
  • and most important, spin off Scratch Orgs within minutes through script to quickly work on POC or package based development

What are scratch Orgs ?

Salesforce DX can be enabled for any Salesforce instance and they are known as Developer Hub. One Developer Hub can have multiple Scratch Orgs. Scratch Orgs are temporary Salesforce org which can be created quickly and metadata can be deployed from SCM. These kind of Orgs can be used by developers to perform quick proof of concept or build and test packages. Once package is build and saved back on SCM, scratch org can be destroyed easily. Continue reading “Getting started with Salesforce DX – Salesforce Developer Experience”

Behold Yourself – Summer 17 is here to break legacy Visualforce Navigation code in Lightning Experience

In Summer 17, URLFOR method in Visualforce would not work in Lightning Experience if used directly. Even sforce.one API is not fully compatible.

You read it right. Its not Locker Service that may break your code, but Summer 17. If you have legacy Visualforce page, which needs to navigate to Lightning experience and URLFOR is used directly, then chances of getting below error are very high.

Salesforce Summer 17 - URLFOR Not working
Salesforce Summer 17 – URLFOR Not working

In above screenshot, I got MALFORMED_ID : malformed Id error in one of my Visualforce, where I needed to navigate to new Account record. Continue reading “Behold Yourself – Summer 17 is here to break legacy Visualforce Navigation code in Lightning Experience”

Export or print code review feedback generated by Salesforce Lightning CLI

How to print or export code review feedback report generated by Salesforce Lightning CLI tool

Update : We can use this heroku app to scan Lightning component online and get code review feedback. Complete source code is available here. We don’t need to install Lightning CLI until its project compliance issue.

Salesforce Lightning Component - Code review - Javascript lint
Salesforce Lightning Component – Code review – Javascript lint

In this post, we discussed that how Lightning CLI can be used to get a code review information of custom Lightning component. However, code review is either printed or exported as a file in text or JSON format. Question is, how to get Lightning component code review feedback in HTML or PDF format ?

I tried various options available here however there were no way to export code review feedback generated by Lightning CLI. Output generated by Lightning CLI is not presentable to business executives or clients.

Finally, I came up with very simple Heroku application, which can be used to get Lightning CLI code review feedback in HTML or pdf format. We need to run below command to get CLI code review in JSON format. Continue reading “Export or print code review feedback generated by Salesforce Lightning CLI”