Share Content on WhatsApp Using Lightning

Posted on Updated on

Hi All,

Whats-app is one of the most popular messaging apps in the world.One third of world’s population is using Whats-app on their smartphones.That is why I thought to implement a functionality by which user can share content on Whats-app. I implemented this with Salesforce1 Lightning.

I got this idea from here.
If you need complete code you can send me an email on

In this demo I am showing you user’s feeds with WhatsApp Share button. When you click on this button it will ask you to share your specific feed with any contact in your mobile device. When complete it will look like this:

Here is the complete code let’s walk through it :

public class FeedItemController{
    public static List<FeedItem> getFeedItems(){
        return [SELECT Body FROM FeedItem WHERE InsertedById =: UserInfo.getUserId() ORDER BY CreatedDate DESC LIMIT 10 ];

In this controller I have created a method getFeedItems() to return feeds of current logged in user.

<aura:component controller="bklightning.FeedItemController" implements="force:appHostable">
    <ltng:require styles="/resource/whatsappfiles/whatsappfiles/bootstrap,
    <aura:attribute name="feeds" type="FeedItem[]" />
    <div class="page-header page-header-anchor">
    	<h1>Share Your Feeds</h1>
    <div id="msg" style="display:none;color:red">
    	Please share this article in mobile device
    <aura:iteration items="{!v.feeds}" var="feed">
        <div class="card">
          	<div class="card-heading">
          	<div class="card-detail">
            	<a data-text="{!feed.Body}" class="whatsapp w3_whatsapp_btn w3_whatsapp_btn_large">Share</a>

Resources for this Lightning Component could be found here jQuery , Bootstrap.

	loadFeeds : function(component) {
		var action = component.get("c.getFeedItems");
        action.setCallback(this, function(a) {
            component.set("v.feeds", a.getReturnValue());
    whatsAppJS : function(component){
        var isMobile = {
            Android: function() {
                return navigator.userAgent.match(/Android/i);
            BlackBerry: function() {
                return navigator.userAgent.match(/BlackBerry/i);
            iOS: function() {
                return navigator.userAgent.match(/iPhone|iPad|iPod/i);
            Opera: function() {
                return navigator.userAgent.match(/Opera Mini/i);
            Windows: function() {
                return navigator.userAgent.match(/IEMobile/i);
            any: function() {
                return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
            if( isMobile.any() ) {
 				var text = jQuery(this).attr("data-text");
                var message = encodeURIComponent(text);
                var whatsapp_url = "whatsapp://send?text=" + message;
                window.location.href = whatsapp_url;
            } else {

In WhatsAppLightningComponentHelper.js whatsAppJs() method is used to share content on Your WhatsApp.It can support any mobile device but we know that Lightning app is not supporting Android and other devices so it will not work for them.
I did not change code because I hope Lightning will support other Mobile Devices in future.

Please change Namespace to your Namespace before running this code.

Thanks 🙂

2 thoughts on “Share Content on WhatsApp Using Lightning

    SutoCom said:
    July 4, 2015 at 9:14 pm

    Reblogged this on SutoCom Solutions.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s