Create collapsible panel component in Lightning

In previous blog post, we saw that how Lightning component bundles are related to each other and how to create simple Hello World component.

In this post, we will create very simple yet powerful reusable lightning component for collapse and expand panel. This time, we will skip basics of lightning and directly start with code.

Complete component is build with plain javascript and CSS, no library used.

Lightning CollapsiblePanel Component - Collapsed

Lightning CollapsiblePanel Component – Collapsed

Lightning CollapsiblePanel Component - Expanded

Lightning CollapsiblePanel Component – Expanded

 

Continue reading

Continuation object in Apex – Asynchronous callouts for long running request – Live Demo

We may run into scenario in Salesforce project, where we need call external web service but no need to wait for response. Response from external web service can be processed asynchronously and once processed it can be presented in Visualforce page.

We can accomplish this by using Actionsupport or Javascript remoting. However, this is possible with using Continuation method as well.  In Continuation approach, we can call external web service and inform that which callback method should be used to  process response. After execution of callback method, data is presented in visualforce page.

Execution Flow of an Asynchronous Callout - Image from Salesforce documentation

Execution Flow of an Asynchronous Callout – Image from Salesforce documentation

Below code demonstrate complete usage of this.

Continue reading

Getting started with basics of Lightning Component

As you might already know that next big change in Salesforce is introduction to lightning components. As technology is changing rapidly and to take advantage of cutting edge innovations in web technology, Salesforce doesn’t want to stay behind. If we see trend, all major platform has introduced component based design like Polymer, React, Web Components, Angular 2.

We will be discussing basics of Lightning components in this post and how Lightning application, component, controller, helpers and Apex controllers are connected with each other.

Lightning components are based on open source UI framework for web development. Every Salesforce organization already has aura documents available in their instance and can be opened by navigating to http://instance.salesforce.com/auradocs. You can also visit my other blog post explaining FAQ of lightning and Lightning Trailhead module.

In below image, I have tried to explain at high level, how different JavaScript files are related in Lightning components, there are many other parts as well, but I tried to keep it short and simple.

Getting started with lightning components

Getting started with lightning components

Continue reading

All about Upsert and External ID in Dataloader and Apex – Videos

You may be wondering that there are tons of articles available for upsert operation and what is need of one more blog post. I wanted to note everything important about upsert operations using datalaoder and Apex with identified gotchas at single place, and that’s why its here :) .

External ID is field in Salesforce to say that this field is primary key in external Database which can be used to identify that external record exists in Salesforce or not ? There are many benefits of external key like :

  • It can be used to identify if record exists or not and record automatically inserted or updated using upsert operation
  • Upsert operation is supported by Dataloader, Apex and API
  • Any field marked as external id is indexed and can be used in SOQL or report filter
  • You can create Parent child record in single statement in Apex

Using Upsert operation to create/update child record and relate to existing parent record with help of External Id

Lets assume that you have list of contacts and Account in external SQL Server database and you want to import those Account and contact weekly. It is possible that you have already imported contacts previously so don’t want to duplicate records if already created in Salesforce. To solve this problem we can use external Id on Contact and use upsert operation on dataloader. Let’s assume external Id field on Contact is “SQL_Server__Id__c” (I am assuming that Account records in Salesforce also have external Id and records are already imported. Same below steps can be used to import Account record as well). Continue reading

Addthis plugin for wordpress – serving request to b.scorecardresearch.com

Recently my website was slow and I tried to search for possible causes.

While checking network traffic in google chrome, I found that my website was making request to “b.scorecardresearch.com” and reputation is not good at all for this site. I did my research on wordpress forums and found that “addthis” plugin was making requests to this site and there is no way to restrict it.

I am writing this post, so that readers would know that one of WordPress plugins that makes request to “b.scorecardresearch.com” is addthis. I have decided to remove this plugin from my blog as I don’t want my visitors information to be traced and slow website.

Using Dataloader and ANT to backup Salesforce data on FTP server – Video

We will be using command line dataloader from Salesforce and ANT script to extract data from Salesforce and backup on FTP server. I would recommend to go through this article first to get familiar with basics of commandline dataloader and followed by this article to get some insight that how we can use ANT with dataloader.

There can be hundreds of use cases where we need to backup data from salesforce and we have thousands of options. We can use Jitterbit, Mulesoft, Dataloader.io or some big ETL tools like BOOMI or informatica. However sometimes clients are not willing to pay hefty  amount on licensing cost of ETL tools and I love open source. In this article, we will be using open source solution to very common problem of backing up data on FTP server.

Complete code is available on my github account as well in case you need it.

Use Dataloader and ANT to back CSV file on FTP Server

Use Dataloader and ANT to back CSV file on FTP Server

Considering you know how to use command line dataloader, first challenge would be how to get it worked using ANT. Below code snippet show how we can create ANT macro to invoke dataloader to extract data. Continue reading

Using Selenium to test workflow field update action – Salesforce automated testing – Video tutorial – Part 2

We have already discussed basics of selenium and how we can use this tool for automated testing. Here we will see how we can take advantage of Selenium to test workflow field update. in this article we will create a simple workflow rule on Lead object and update “Description” field by adding fields “Number of Employees” and “Number of Locations”. We can use selenium to test if workflow is working or not ?

Salesforce Workflow rule - field update on Lead

Salesforce Workflow rule – field update on Lead

Continue reading

Create and update records using Javascript button in Salesforce- Ajax Toolkit

On this blog we have already seen “how to use Ajax Toolkit to mass update records” without writing any Apex code. In this article as well, we will use Ajax Toolkit to add custom button in Account page layout and update record.

There are endless possibilities and use-cases where this approach can be very useful in Salesforce projects and can be accomplished by Salesforce admins. Lets say we want to create child record on click of button, Update current record on basis of some logic, Update hidden fields, execute existing Apex code using Javascript and so on. All of these can be implemented wthout writing single line of Apex code, Trigger or Visualforce pages.

In this post, we will add custom button on Account detail page and execute Javascript to update Account name using Ajax toolkit. This is just proof of concept and any other field can be updated.

Creating Custom button :

Navigate to “Customize | Accounts | Button, Links and Actions”.

Create new button of type “Detail Page Button” , behavior “Execute Javascript” and content source “Onclick JavaScript”.

Update Record using Javascript

Update Record using Javascript

Continue reading

Getting started with React

React is open source Javascript library used by Facebook and currently very popular amongst web developers to create user interface. React can be used as View part of MVC design pattern with powerful templating feature supported by “JavaScript syntax extension (JSX)“. React focuses on component based development where each components has its own life cycle. Once of exciting behavior of React is its unidirectional data flow from Parent to child components. React is different than AngularJs in such a way that React passes data in unidirectional however in angularJs data must be available to $scope variable (bidirectional binding). Reusable components in AngularJs should be created as Angular directive however in React every component can be reused.

React Javascript library by Facebook

React Javascript library by Facebook

In this article, I will show very simple Hello world program using React framework.

<html>
	<head>
		<script src="http://fb.me/react-0.13.1.min.js"></script>
		<script src="http://fb.me/JSXTransformer-0.13.1.js"></script>
	</head>
	<body>
		<div id="main"></div>
		<script type="text/jsx">
			var HelloWorld = React.createClass({
				render : function(){
					return (
						<h1> Hello World</h1>
						);
				}
			});

			React.render(<HelloWorld/> , document.getElementById('main'));
		</script>
	</body>
</html>

Output : Hello World in h1 tag. Continue reading

Selenium and Salesforce – Salesforce automation testing – Video tutorial – Part 1

This is first post of multi-series article on using Selenium with Salesforce for Automation testing. Testing has always been integral part of any software development life cycle and Salesforce has already taken it to next level by making mandatory to have 75% of code coverage before any code deployment. These apex test classes, however has its limitations where we can only test Apex code written. I have seen most of Salesforce project ending with manual testing. Audience for this series is not only developer but Salesforce admin and of course manual testers as well and please feel free to drop comment throughout this series if I left any area or topic uncleared.

What is Selenium 

Selenium is a portable software testing framework for web applications. Selenium provides a record/playback tool for authoring tests without learning a test scripting language (Selenium IDE). It also provides a test domain-specific language (Selenese)[1] to write tests in a number of popular programming languages, including Java, C#, Groovy, Perl, PHP, Python and Ruby. The tests can then be run against most modern web browsers like firefox, Chrome, Internet explorer. Selenium deploys on Windows, Linux and Macintosh platforms.

Selenium and Salesforce

Selenium and Salesforce

Continue reading