Quantcast
Channel: cloudy
Viewing all 29 articles
Browse latest View live

Named Credential and Auth Provider Concept In Salesforce-Linkedin and Salesforce Integration

$
0
0
This is my first technical post after I have moved to Texas from Bangalore and Hope I make it interesting read 

One of the common challenges when Integrating salesforce with other external system which supports Oauth 2.0 has been to manage the Oauth 2.0 flow using custom objects in Salesforce ,where there was need for some temporary storage for storing either the access token or the refresh token or an alternative approach was to do authentication every time user makes a request to other external system.


The below diagram summarizes oauth 2.0 and for more information would suggest you to read some articles in google or wiki




If i tell you for some system like google,twitter,facebook,Linkedin,google I dont have to handle Oauth 2.0 myself with lot of code and salesforce will automatically take care of it ,I don't think you will trust me .

So in this blogpost ,I will be integrating linked.in with Salesforce with very minimal code and will pull my resume as a chatter app,so grab a coffee and lets together continue doing this interesting piece of integration.

Before we do lets see how much complexity it involved in past ,

Terry Luschen  is an awesome blogger on Salesforce Integration with external system and I picked his post as starting point 


So i see that we have some 30 to 40 lines of code just to establish connection and then there is hint on how to handle refresh token and oauth token .This is excellent post almost an year back and with SFDC coming with Named Principal and Auth Provider makes life simpler for these type of Integrations.

Business Scenario-Handshake between Salesforce and Linkedin as a Proof of concept and a decent technical guide to build more robust functionality like searching linkedin data,showing linkedin feeds ,fetching related contacts to increase more contacts .There is lot of business process that you can tie up and build some cool stuff and add business value with linkedin data .

1)Configuration of Auth Provider

In Salesforce Environment navigate as below path

Administration Setup>Security controls>Auth. Providers

Fill this form and leave blank for consumer and Consumer Secret


Note URL Suffix is automatically filled once we have name.

Please note Callback login URL for next steps .This will be fed to the LinkedIn app.

2)Configuration of LinkedIn Application 

Navigate to https://developer.linkedin.com/  and click on My Apps for creating a sample application
Click on Add new App for adding your Application .

All the information is self explanatory that are required to filled except for Oauth 2.0 redirect URL which is very essential .This needs to be fetched from salesforce Auth Provider Setting .Salesforce Auth Provider once it is saved ,it will provide us with necessary URL

You will see a consumer secret and consumer key once linkedin form is saved 

The Consumer Key and secret needs to be updated back into the Auth Provider so complete the Auth Provider setting

3)Configuration of Named Principal 

This is an excellent feature thats been introduced in Spring 15 and it makes life excellent to avoid the lengthy code just to authenticate ,below is how we configure it for linkedin API

Administration Setup>Security controls>Named Principal

Select Oauth 2.0 as your authentication mechanism and Auth provider as one you just created and Identity Type as per user 

Now from API guide the URL that will be common will be https://api.linkedin.com/v1/

Hence use that as a URL for named Principal .

Also dont forget to check Start Authentication flow on Save if you need to run oauth .On Save oauth flow will happen and there will be success message if authentication is successful.

This is how the prompt will show if all successful .

Once you confirm this app to allow access ,you will see a success prompt or warning prompt confirming all success and registered .

 4)Need now apex magic to complete

Now using named principal we will do callout and fetch data inside salesforce ,parse from JSON and show in UI .

Apex code for parsing class is as below




The Code for controller doing callout and fetching data is as below


The next steps are creating tabs for VF and adding as a Subtab Application .Here is how finished product looks like .Obviously with some CSS you can make things look more fancy



Now one final question is what will happen when other users login and try and see their app .Will the app show them their profile .

When we created named principal we said our Identity Type is"Per User".

5)Assigning Permission set to other Users so that they can add their external source

So lets say I have another User in my org and he navigates to the LinkedIn profile page ,he will see his profile Info from the linkedIn if he follows below steps assuming administrator has assigned a permission set with access to the Named principal 


Each user should be trained to go to My Connected Data in their personal set up and add this as external data for working of app




Some more cool Idea would be show data in bootstrap format and make UI responsive ,Build some linkedIn search engine via API and lot .

The power of "named credential" is I have no code to run my oauth .

Please feel free to comment what you feel on this blog .I have common complain that my blogs receive no comments and no feedback :(  


Responsive Bootstrap Calendar In Visualforce

$
0
0
Making Visualforce work for all forms of devices is common ask these days .Gone are they days when we used plain old school Visualforce with pageblocks and pageblock tables to present data to the User .

The number of mobile devices has dramatically increased these days and technology is moving rapidly to mobile devices.Everyone prefers viewing the information on handheld devices along with viewing on desktops and laptops .

Responsive web design (RWD) is an approach to web design aimed at crafting sites to provide an optimal viewing experience—easy reading and navigation with a minimum of resizing, panning, and scrolling—across a wide range of devices (from desktop computer monitors to mobile phones).

There are some cool frameworks out there that ease development of a web page following responsive design patterns .

Some of them I would like to list in case you have not come across them 






With little bit of HTML and CSS knowledge you should be able to start .HTML and CSS and JS skills are primary for any framework .

So this blogpost is sharing how to build a responsive calendar using visualforce .

Before beginning thanks to the author serhioromano for amazing blogpost on how to use bootstrap and  Jquery to build a responsive calendar .Check his below blog that speaks lot about his work 


http://bootstrap-calendar.azurewebsites.net/


Please kindly note the real rock star is  serhioromano  who has built this .My work is just making it adaptable to Visualforce and force.com platform.

Business Use Case


1)Need a calendar data from custom object and out of box salesforce calendar is not an option then 


2)Building a cool client portal with custom Visualforce and need a calendar to show events and tasks 


3)Building a public website and would like to show your company events on a calendar .


There are lot more Use cases I am sure you will discover ,having a calendar view of data helps lot.

Solution Approach


1)Reuse existing code library from  serhioromano  github repo and build an apex javascript remoting class that feeds the JSON data to the calendar api function .

2)Provide flexibility to the developers and Admin so that they can customize the calendar for any Sobject and any field by simple one liner code change .


Demo Link


I have created a public site to host my page for ease of view and please observe the responsiveness of this calendar.


http://webzone-developer-edition.ap1.force.com/webzone/Calendar








Code 


The entire code for this can be viewed from my github repository


https://github.com/msrivastav13/Bootstrap_Resposive_Calendar


Also I have unmanaged package from where you can install in your org for playing around

Use this URL to install the package into any organization:

https://login.salesforce.com/packaging/installPackage.apexp?p0=04t90000000FUls

Note: If you are installing into a sandbox organization you must replace the initial portion of the URL with http://test.salesforce.com


What line of code do I need to change for changing to other objects ?



The above lines are embedded in the component  Responsive_Calendar_View  component and a developer needs to change this line .The definitions of  attribute is provided below














In case of any issue inspect your browser console or contact me or leave a comment below .

Hope you liked this and happy coding :)

Integrating Google drive with Salesforce Using File Connect Feature

$
0
0
Summer 15 release is out and lot of features to dive into .One thing that caught my immediate attention was ability to integrate Google Drive with Salesforce through lightning connect .

It hardly took me 20 minutes to get this working on my developer edition and I am super excited to highlight step by step procedure to configure this .Please note salesforce did an amazing job on the documentation for this .Its crystal clear to me .


Just to add little more flavour with screenshot would help many folks I believe who have no time to read through documentation .(I strongly suggest please read through release notes )






Step 1

Enable File Connect in your instance .Please note since this is summer 15 release feature i did this in pre-release org 



Step 2

Allow your users to access google drive .Follow the step by step instruction documented in below link


Below shows the permission set that I have created .Remember to check file connect cloud permission 



Step 3

Create an authentication provider for Google Drive

The first step is to create a project in developer console of google 

i)Navigate to the developer console of google using below link 


ii)Enable Drive API and Drive SDK 


Follow below article path on more info .I am attaching screenshots to help you guide 



iii)Create web application so that you can obtain client secret and consumer key to fed back in salesforce



Step 4

Create a google auth provider in SFDC using auth provider configuration listed in document.Please note to specify type as the OPEN ID in the auth provider settings .

In the auth provider  settings you will need to provide client secret and consumer key to the SFDC from google and feed back the redirect or callback URL generated from SFDC back to google application  


Step 5

Create External data sources .Note the type as "File Connect:google drive" .This external data source needs to be added to permission and if your authentication is "per user" type your end users needs some training on how to add this from My Settings tab .Choose Oauth 2.0 protocol .


Validate and sync all objects .You will see an external object created in SFDC and also you will notice if you navigate to chatter files you will see all the data .



There are bunch of other features added as well in this release 

1)Files tab now can provide search layouts for searching these files and no need for searching from chatter

2)Focus Search on a Single External Data Source

3)Files Connect could previously access only standard fields from external data sources. But in Summer ‘15, you can add any custom fields and display them in unique search layouts.

4)Lookup Relationships Supported for Files Connect External Objects

Read through release notes and explore more .Lot of solid stuff in this release and make me wonder "Do salesforce engineers ever sleep". They sleep or not but for consultant like me ,they keep me awake by adding lot of features to the Product .

Hope this feature will make your customer happy that you can access all information from google drive now .

Lightning Components Framework Learning Resources

$
0
0
Building custom lightning components will be a required skills for salesforce developers in coming years .Whenever there will be need for building SPA (Single Page Applications) for Salesforce 1 ,using lightning components will be one of the architecture choice .

Although  there are multiple frameworks that one could use which includes angular,backbone,ember etc but lightning is from salesforce and uses aura framework hence it will be really good candidate to consider for building SPA applications .

The aim of the blogpost is to share some useful resources  on how I have gained some expertise around building lightning components .

If you are familiar with javascript framework or at least have hands on experience with one of them ,your learning curve for lightning components will be pretty small.If you don't have none or never worked on Javascript ,you may like to go through some of javascript course and get yourself up to speed.

The key point to understand will be while building lightning components  the javascript code will follow event driven pattern .Each component can emit events and other components listen to  different events and perform server side logic .You will find minimal server side calls will be made and rest of Dom manipulation will happen with client side javascript controller and javascript helper .

Lets take a look at  various resources that helped me to learn lightning components 

1.TrailHead



This is by far the best methods to learn about how to build lightning components .The Trailhead has a module Lightning components that will force you to do hands on exercises and passing them you will feel confident enough that you have understood basics of lightning component  framework.

Trialhead  on learning lightning component is located at below URL



2.QuickContacts App Tutorial from Christophe Coenraets


This tutorial is amazing and thanks to Christophe for all awesome work .This tutorial will walk through building a quick contact app step by step .

The tutorial can be found in the below URL 



3.ReidCalberg Newbie Lightning Component Notes


This notes is quite comprehensive and thanks to author for excellent write up .Below is the URL where you can grab the notes and start working 


4.Video Tutorial from Salesforce MVP .


This video is good resource and worth watching all the modules


5.Paul Battison Videos 


Paul is a salesforce MVP and I love video tutorials from him .He makes difficult concepts looks lot easy .He explains code in very simple english .I subscribed to his youtube channel ,He has put 5 videos so far on lightning and i am looking forward to more of them .

Below is the link to Paul's channel


Below are lightning specific video links 







6.Jeff's Tutorial


We all love Jeff blog and below is link for  tutorial from him


Other Helpful Resources

Apart from all this ,salesforce lately added a new tag <ltng:require /> and below blogs will help us understand more on how to incorporate external JS  libraries in our lightning component using the provided tags





Apart from all this for deep knowledge work with lightning developer guide


I hope you have enough resources to start building lightning components yourself.



Dallas MeetUp -May 27

$
0
0
Last night  Dallas meetup was so much fun .I had the chance to present on Angular + Bootstrap + Visualforce with sample code .

I am so glad it went really well and also provided me opportunity to connect with lot of local folks who are excited to be a part of Salesforce Community .

Quickly wanted to share the code sample that I presented at meetup .

A simple responsive page to add Account Card was built using bootstrap and JS remoting along with angular concept of using modules .

The Presentation is at slideshare so that if you missed my session you can go through the same .It covered basics of bootstrap and angular JS and then explained the code snippet of how to use angularJs in salesforce .



Dallas meetup session  on Bootstrap + Angular + Visualforce from Mohitkumar Srivastav

The code samples I have shared on Github

Apex Controller


Visualforce Page

Hopefully this session was helpful .Please let me know how you feel about the whole session .Thanks

Installing Lightning Package Plugin On Sublime Text On Windows 8

$
0
0
Building Lightning components is next task we will all be bombarded with as Lightning from salesforce emerges as a mature framework .

Having proper developer environment set up locally helps us to code effectively and helps to organize code .Subime text 3 editor makes editing files simpler and mavens mate plugin for writing apex and VF is great.

For lightning components we luckily have a package control plugin which we can install on top of sublime text and edit lightning components directly using mavensmate .

Already Raja from Salesforce describes how to install the plugin on MAC machine .Please watch the below video from him 


For windows machine i have one below ,if you are using windows I hope below video is helpful


Salesforce Lightning Components Hello World SPA Project

$
0
0
Lightning component framework from salesforce is amazing add on to platform .To build Single Page Applications there are lot of modern  framework like angular ,backbone,ember,meteor,react Js and lot more.Every framework comes with its own advantages and disadvantages .Salesforce lightning is one among them which is fast maturing .

I was reading through lightning component developer guide recently and just to explore  art of possibilities I did a quick Lightning SPA project that shows below listed  functionality:

  1. Quick Add ,Edit and Delete Account to Salesforce from standalone lightning App or Salesforce 1
  2. Using bootstrap library for UI in lightning project
  3. How to achieve simple navigation using CSS toggle 
  4. How to display error messages from server by dynamically creating lightning component markups
  5. Effective use of Events to communicate between components .
Lets take a demo video of the application before deep dive into some of the awesome stuff I have



Some of the key points I noted while doing this SPA Project are as below

Events :

Events are really cool .If you are not familiar with event driven pattern then you will have some tough time .In event driven pattern key is two components communicate with each other using events .There will be  Subscriber component and a publisher component .

Publisher component will publish event using aura:register tag.The events needs to be fired on action from button click or through any events.A simple example in my application when I create New Account ,my edit component fires an event and the main LightningSPA component listens to the Event and performs necessary actions needed 



The below code self explains the principle of firing events and then handling the event back 


Routing:

I miss angular routing here where one could easily navigate between templates .If your application is not running as standalone and you want only for salesforce 1 mobile client ,there are bunch of navigation support provided 


If we need for both standalone and SF1 one way document recommends is using below code

For my app I  prefered old  school approach of toggling using CSS as it makes it super fast .


Displaying Error Message:

Error handling at client side is easier if we dynamically create alert messages .One of the approaches for same is as below 




What are key things that would be needed if you are submitting for security review

  1. Make sure FLS is handled in backend code for apex 
  2. Make sure you do DML access check at backend apex
  3. As far as possible avoid use of third party libraries (We cant totally avoid agree),but would recommend to use framework specified tags 
  4. Name space your bootstrap .There is an online tool that can help you do this https://bootstrap-namespacer.herokuapp.com/
  5. Avoid usage of aura:unescapedHtml
  6. On page load init handlers avoid DML .
Few more documented below



The fun part 

I am sharing all code in my github library .So feel free to pull and do changes ,suggest changes ,tweet me concerns .







TrailHead Goodness

$
0
0
Most of my friends who come from Java world into apex often ask me about where can they find quick tutorial on CRM lifecycle and quick hands on tutorial on how to use Account Management ,Contact Management ,opportunity management and so on.

TrailHead has got some modules now to explain all of this in depth .

Lets summarize each of the modules and see what they help us learn

Account & Contacts














If you quickly want to learn how to create some Test Accounts and Contacts and understand relationship among them worth spending your half an hour with this module


CRM Basics














Now this may sound silly if you know the concepts but fact is most of developers we dont think of business case for which we spent hours writing code .The basics of salesforce starts with knowing CRM .This module for me should have been first module of TrailHead .Never too late .Grab a coffee and spend some time working on this Trail Badge .


Leads and Opportunities














I would open this module for Training end users .Before we onboard our sales or marketting team ask them to get this badge and I am sure this will help them to gain better understanding on how salesforce will increase their productivity.Explain them the significance of keeping data clean and ask them to create some test data in training environment before they start using the system in their Production Environment .

Event Monitoring

If you are a system architect I would recommend you to learn more about Event Monitoring module .This will give you great insight of how to track various events like login ,logout ,usage of API ,UI clicks .All this will help to draw inference about how the system you have built is being adopted .

Adoption is key metric and this module will help you understand how to pull event log files from SFDC and how to report and analyze reports .















Finally if you are going to dreamforce how cool it is to gather information prior to that and do some homework.Dreamforce module is amazing way to prepare you for this .















If you are a geek and Nerd ,then do some Projects and get hands dirty .Follow the Trailhead Project link below

https://developer.salesforce.com/trailhead/projects

Finally grab all Trailhead badges as I did and beat me up :))





Lightning Connect Apex Adaptor

$
0
0
If your organization has already subscribed to the Lighting Connect feature(This is available based on Subscription with additional fees .Contact your salesforce AE to learn more ) to create External Objects,it is good to know that apex can be used by your developer to expose data from any system which uses SOAP or REST as external Objects .

The advantage of using External Objects will be saving some storage space .The data will not reside inside salesforce but can be viewed in salesforce User Interface just like any other objects .

There are number of limitations worth noting before you decide to go with external objects and salesforce documentation can help you in regards to this 


There are lot of chances that you need data only for reading from external system and may later run apex to convert few into transaction data .One of the ways to address this business use case can be using lightning connect .There may be millions of data and with lightning connect you can keep it outside salesforce but still use salesforce interface to view ,search and use apex to convert some to SFDC native objects .

When lightning connect feature was launched you needed an adaptor to convert data into Odata before you could actually consume and bring into salesforce as an external object.

Its good to know you dont need an Odata now and an apex written by developer can be used by salesforce administrators to bring any data via SOAP or REST to salesforce .



Aim of the blog Post:

   The main aim of this blog post to show an example to developer community on how to extend  data source provider and data source Connection classes to build external data source in salesforce.

We will connect to a simple REST end point available for Non commercial financial  purpose .To explore more about this webservice please read below 


Exchangerate Lab provides us free end point for non commercial use to fetch some data that shows latest currency rates for selected Currencies .Please note the aim of calling this webservice is just to demonstrate the Lightning connect feature.


  • The first step is to create a DataSource Connection class.

The Connection class will provide 
  1. Metadata definition of the external schema which admin of salesforce will generate based on need by just clicking a button
  2. Query method to query the data from API.
  3. Search method to implement the search via global search
  4. Filters and pagination if needed can be implemented in query and search methods
  5. Write a JSON parser for mapping data to fields
The below code is self explanatory and it connects to exchangedate labs to fetch currencies and exchange rates


  • The next step is to create a Data source Provider class that describes the functional  abilities like authentication mechanism ,capabilities provided by the data source
The below code shows an example class and format 

The below shows the video on how Admin will configure with simple clicks for magic 




References:

https://help.salesforce.com/HTViewHelpDoc?id=limits_external_data.htm&language=en_US

https://developer.salesforce.com/blogs/engineering/2015/05/introducing-lightning-connect-custom-adapters.html

http://docs.releasenotes.salesforce.com/en-us/summer15/release-notes/rn_forcecom_external_data_apex_adapter.htm

Migrating to Lightning Experience with Trailhead

$
0
0
I have been fan of Trailhead since I used it for first time to learn on how to build lightning components .Trailhead makes learning fun and enjoyable .You get to learn at your own pace at your own time and at your convenience .

Many of you would have heard salesforce launching new User Experience which is seamless experience of your salesforce data on any device size ,right from your apple watch to your apple macbook pro or air .

Migration is always not easy .Its cultural change .It will come with time and people will require some support and Training to get trained .

Trailhead is our friend that will guide us in right path as we transition from our aloha look and feel to this new exciting lightning experience .Whether you are Developer ,Architect ,Customer or Partner related to Salesforce ,Trailhead has content for everyone .

Lets Summarize the content that will make you feel confident and comfortable while you go through each of these  new modules in the Trailhead

Admin Trail




For Admins Migration to lightning experience means they need to be familiar with below


  1. How can they customize or change layouts ?
  2. How can they configure objects and relationships?
  3. How can they enable their users to this new experience ?
  4. What should be the Roll out strategy while they migrate the users to new experience ?
  5. Where can they configure actions and what are the differences with respect to old aloha UI ?
Lot to answer.If an admin goes through all the modules present in above Trailhead I am sure you will get to the meat of the content .

Developer Trail


With new Lightning ,Developers will need to worry about following 

1)What will break in their existing code and wont work with lightning ?
2)How can they make their Visualforce code work with lightning ?
3)What is Salesforce Lightning Design System ?
4)How can they detect via code how to differentiate between aloha environment and lightning environment ?
5)If you are an ISV ,what factors you have to consider when you build your visualforce pages ?
6)What changes app exchange packages will need to get the Lightning Certified Sash?

All the answers to this has been embedded inside the Developer Trail for Lightning experience .

Sales Rep Training


Sales Rep Trail will enable your organization to train your sales reps 

Asking Sales Rep to go through this Trail will help them use the system effectively .Your sales rep will learn below in detail

  1. How to work with leads and opportunities with new user experience 
  2. Various tools that will help them to track their performance and help them sell effectively
  3. New reports and dashboards and chatter feeds .
This is the first content for end users from Trailhead team and step definitely in right direction

If you are a new admin there is one more and you can start right from there 


Trailhead URL


Also don't forget to share your progress on twitter and share your badge selfie as I do often 



















If you love projects ,there are few new projects as well  for you 

https://developer.salesforce.com/trailhead/projects

ReactJS and Salesforce Lightning SLDS 101

$
0
0



Having worked on writing visualforce page with React using Salesforce Lighting Design System I would like to share some experience  through this blog post.

Clearly  ReactJs can cherry pick difference in the DOM structure and updates the only part of DOM that is part of component, you read this post to know little in detail about ReactJs on getting started and understaning basics.

ReactJs with Remote Objects

Salesforce Remote Objects allows you query salesforce without glueing apex and purely writing UI intensive apps see here. I wrote code snippet that consume remote object and query salesforce, on top of it, he have imported Lighting Design Systemto fabricate the UI.


Salesforce Lighting Design System (CSS from Salesforce)

Salesforce have opened stylesheets now, for the world to incorporate Salesforce user experience with new Lighting UI. Out of the many components available, I will be using datatable component and header components to carve the layout of this page.


Single Page Application (SPA)

To showcase, component driven functionality with React, I wrote single page, keeping concepts simply to absorb, to give a kick start and direction for consuming this framework in the universe of Salesforce.Below is visualforce page that consume React component, click below to open in new page




Code Walkthrough

If you carefully notice, we reference all external javascript through CDN and some hosted on github, learn how to use Github as CDN with Salesforce.



The components are divided from top to bottom in two prime category of components nested

1. Account View : Parent component nesting child component
2. Account List : Child component polling Salesforce to list data rows

To visualize neatly you can see this tree structure shown below

  --Accountview
      ---AccountList
--Account 1
--Account 2
--Account 3


As you can see three component are primary designed here, Account Component is component to draw header of the table (list) declared as below


Secondly, AccountView is nesting drawing the view of table and nesting list component that queries Salesforce in the back




AccountList binds data into Tabular view and generates table



Notice, the use of  promises with Visualforce Remote Objects using code from in this repo (check it out) and not a single line of html code is written on visualforce end besides skeleton of the page, all code is written in JSX compiled into Javascript, also note for converting React JSX to javascript in production release, you can do it through Node React Tool


Whole code snippet is embedded below is ready to be served out of the box (import all required resources from CDN)


Setting up Dev tools for Salesforce Project that uses ReactJs library

$
0
0
Problem Statement :

You are building a visualforce page which has React JS library and you want to split your React code into multiple files as per javascript best practices and maintain your React JS folder inside your mavensmate project .You need your tooling to help you with local development in offline as well you are in search of a convenient mechanism to handle pushing your changes to SFDC static resource with minimum effort . 


The static resource once zipped in salesforce ,its hard to edit even for awesome tools like mavensmate .Mavensmate tool is a well known IDE and it comes with resource bundle for this process where one can create a bundle with JS ,CSS and image files and then convert these bundles to the static resource .


This process will not work for the React JS files as React JSX needs to be transformed into JS files before the actual code is shipped to the Production .


There are multiple ways to solve this tooling problem and in this post we  will set up our tools for salesforce project using combination of gulp and mavensmate


Prerequisite:

  1. You have node installed in your system
  2. You understand gulp.js (Using gulp you can automate your workflow build for JavaScript Projects)
  3. You are in process of learning React JS and understand the library
  4. You are familiar with mavensmate IDE for apex and visualforce development
In my last article we created a simple page with React and all code was inside the single visualforce page  making it harder to maintain and debug .We will use the same Visualforce page and I will walk through the process of how we can be more structured and modular making life simpler for debugging and deploying and of course having fun by doing development locally .

To get started you can clone the repo below and have gulpfile.js and package.json copied to your project folder and also you can create a sample folder structure for ReactJs as per my git project

Observe the gulp file ,it has two major tasks

1)Build task



This will create a separate folder dist/build and concatenate all JS react modules using browserify(Browserify will transform using JSX to JS files) .Also note in JSX files how we have used require and module.exports function .If you are familiar with node.js this is common pattern to export module and configure dependencies .


2)Zip task



This task will zip our final JS files from build folder and place in our mavensmate static resource folder .Note its ideal to create Static resource on server (Salesforce)and sync to mavensmate so that you have meta xml .Else you will need to create your own meta xml for pushing from mavensmate.(Remember deployment to salesforce need meta xml for each component ).


You will need  node now and once you have package.json and the gulpfile.js you can run install command to have all node modules and dependency configured on your local machine


npm install 

  • Keep your static resource file name and the file name in the gulp file path

Observe the RESOURCE_NAMEParameter and it has same name as static resource and its key assumption here .

Following are the three process you will need to follow once you change code to sync to salesforce server


1)Run gulp build

2)Run gulp zip
3)Save mavensmate static resource file

Note :You can set up gulp default and configure both to happen in one command but my personal preference is to go step by step .

Notice that from previous sample our entire visualforce is reduced so much



To make more things clear lets watch it in action the flow of tooling workflow .You can check my  git repo for entire work 



This is not the end of the world .You can further use jsforce and automate further .Also you can set up gulp watch task to watch only for changes and run your process automatically and deploy to salesforce.

Kindly note that this process or having gulp set up you can do more magical stuff and become efficient .

Lot to expore.Need to make some time and kick some ass :) .I hope you enjoyed this small blog and thanks for your time .

Using Jquery with SLDS for validation and Error Display

$
0
0
Recently I have been playing around with SLDS  design system and for sure this has better component set for building mordern applications with excellent look and feel for Mobile or desktop .

One of the key challenges using this library in visualforce (Not in lightning components) is there is no javascript support for CSS unlike bootstrap  and hence it makes really difficult .This is initial stage and I am sure as more developers dig into this ,they will come up with Javascript for various components .

One reason why SFDC would have left this as an exercise to community is since there are wide variety of frameworks now and each Javascript framework is evolving on its own .Angular is moving towards Angular 2 and React is still in its intial phases (Although this framework is widely adapted now and has its own advantages and flexibility).

Lightning components on the other hand is also fairly new but event driven patterns makes it easier to communicate with server .Lightning components will definitely work well with SLDS and there are already some attempts made to build some components .

Check the below project in Trailhead and its a good starting point to get started with using SLDS in lightning components


I tried playing with SLDS with jquery and feel using simple jquery with SLDS can be really cool architecture to build simple applications .Again i dont say it may scale well and you will see for larger applications it will be better to go with  frameworks .

Aim of this blogpost is to demonstrate a simple plugin that i have built that can handle client side validations and also you can display error or success in SLDS style .

The source code for the plugin is available at below gist 


Lets walk through a simple use case on how to use this .

For demonstration purpose we will building a simple form with SLDS design system and a small apex class that calls a Javascript remoting function to insert Account.

We will need three libraries installed to see a working demo

The apex code for ease of our eyes is below

Plugin set up Instructions

All the visualforce coder needs to handle  in HTML of input tag is to add two extra  attributes declaratively

  1. data-required (Make this to true if you want the field to be required)
  2. data-fieldName (Field label that will be displayed as error )
In Javascript remoting you will just wrap your remoting call with below

if (!validatorSLDSplugin.validate()) {

}


Sample screenshot of how this looks




To display success or error messages or any messages on the screen invoke the validator function display alert as below with message and message class .Note message class has to be from the SLDS library .

From SLDS library the classes are as below
  • success--slds-notify slds-notify--alert slds-theme--success slds-theme--alert-texture
  • failure ---slds-notify slds-notify--alert slds-theme--error slds-theme--alert-texture
  • info ---slds-notify slds-notify--alert slds-theme--inverse-text slds-theme--alert-texture
A sample example of how to invoke the validator is as below for success message

validatorSLDSplugin.displayalert('Record created with Id..'+result.Id ,'slds-notify slds-notify--alert slds-theme--success slds-theme--alert-texture'); Sample screenshot of how this looks
Handling SVG images

One of the pain points of the new SLDS has been how we handle SVG .I ran into an issue where using jquery append function did not work with SVG .To overcome this we have refresh the HTML section again .

The refresh can be done as below in Jquery

j$("#messagewrapper").html(j$("#messagewrapper").html());


I also think same solution can be applied to action:function when re rendering SVG tags .A jquery call needs to be made again with outputPanel surrounded and in oncomplete function refreshing the HTML using jquery .I have not tried this but would love to try and see .(If any of you got leisure time try this and let me know how this goes)

Also observe the image variable that i have used in my page to pass the dynamic URL as a global window object to the plugin .

var imageURL = "{!URLFOR($Resource.SLDS102, 'assets/icons/action-sprite/svg/symbols.svg#close')}";

I hope you enjoyed this post .

This is start and i guess it would be great if all SLDS components can be wrapped with jquery or probably angular directives or react components .Visualforce is amazing tool and for building simple mobile friendly pages ,using Javascript remoting with SLDS and VF would work well with rapid development time .



Using Lighting Out with Visualforce

$
0
0
Lightning out is awesome feature and it is correct way of integrating mashups .With lightning out one can easily take lightning components outside salesforce .Some of the examples of system that can consume this includes Heruko , SAP ,Sharepoint and so on .

For external system mashup you will need to first establish connection with SFDC using connected apps .

There is an excellent  session on this topic .

 I have found multiple blogs demonstrating the concept where the lightning component attribute is set from the data inside visualforce .Some of them are as below

Balkishankachawa.wordpress.com/2015/10/31/lightning-component-javascript-remoting-and-visualforce-page/

http://peterknolle.com/lightning-components-in-visualforce/

In this blog we will see how to get the component values out of lightning into our Javascript variable so that we can continue with  more fun of mixing Visualforce and lightning components .

USE CASE :::

My entire Visualforce page used no apex:form and it used pure HTML ,SLDS CSS and Javascript remoting for actions .Now comes the big change in requirement ,need Rich text input field .

I googled to figure if HTML-5 has rich text fields or are there any native solutions without adding the apex:form element and apex:textarea .Introduction of apex:form implies lot of viewstate and makes page slow .

Lightning components interestingly provide "ui:inputRichText"  which is rich text on the webform  .Exciting !!! ..Now comes the challenge of integrating the lightning component into the visualforce and then grabing the set text from the lighting component back into visualforce .

Using lightning out we can integrate a component into visualforce with few lines of javascript .

We will also see how to use the callback function provided to grab the component attribute value back into our visualforce page 

COMPONENT CODE::

If you are familiar with lightning components its 101 of that .A simple component being embedded .

LIGHTNING DEPENDENT APP:

This is similar to declaring dependency just like how we write import statements in java or node.

VISUALFORCE CODE::

The most important part of visualforce code here is way we have declared a javascript variable and pulled the Component into  global variable to access it outside the component and use right away in our visualforce

         var richtext;
             $Lightning.use("c:RichtextApp", function() {
                 $Lightning.createComponent("c:Richtextcmp", {},
                     "richTextEditor",
                     function(cmp) {
                         // do some stuff
                         richtext = cmp;//Very important
                     });

             });

The final screens are below













The console.log clearly prints the what ever is typed in the editor showing how easy it is to get values out of the lightning component.

IOS and Visualforce in Salesforce 1 app Hicups

$
0
0
Lighting is out and looks like its  the future of customization of Salesforce 1 mobile pages .Speaking of present still we have large number of apps having visualforce page for the Salesforce 1 app build using either angular(or other frameworks ) or plain old visualforce styled to responsive design .

This blogpost is sharing some insights into common issues that I encountered with Visualforce inside SF1 container when I was testing the functionality with iPhone or iPad.


Lets list all of them one by one and list the work around for issues as these have no proper fix and are logged as issues by SFDC


1)Key freezing issue with HTML input tags


This is one of the primary issues that's  really show stopper .If you have a visualforce and you use apex:input or normal HTML input and double tap the cursor on the text field you will notice that your keys are freezed and text you enter dont appear on the input box .


This looks to be serious issue with new version of IOS and Salesforce 1 app .Even you are using twitter typeahead for autocomplete or lookups this issue can be easily observed and keys will freeze once you make selection .


The workaround for this is to include a small script at the bottom of the page that resolves this .Please note this is a workaround until this is fixed officially



2)Not able to scroll the iframe embedded in Visualforce inside SF1 container for iPad or iPhone 

This is another common bug and has something to do with IOS webkit inside SF1 .The workaround is below small snippet that adds scrolling behavior needed



There are also certain things that we need to note about navigation pattern we follow in SF1 specific apps

1)When navigating to the external world the right function to use is as below

navigateToURL(​url​[, isredirect])

If you want SF1 container not to remember the history set redirect parameter to the true state.

2)Use back function to navigate to the back and use redirect parameter as true if you want your page to refresh

back(​[refresh])

Using frameworks to develop SF1 apps can increase the speed of app build .Also for complex SF1 visualforce page if you have too many actions and you are packaging for as an appexchange app its worth to write some automation testing using selenium or using protractor whatever you feel comfortable just to not scratch your head if something breaks later due to SFDC releases or due to some code change during upgrade.

I hope you enjoyed this post and will help you troubleshoot issues with SF1 app

Trailhead Awesomeness Continues...

$
0
0
Last night I completed new modules and new project on Trailhead and I must admit Trailhead continues to impress me .Its been one of the best online training resource we have to get trained on force.com platform .

Lets talk about what will you learn once you complete these new modules and why it is worth to spend time on these

Boost your Apex Integration Skill set

Apex Integration Services


One of the key challenge for force.com developers who are new to the platform is they lack knowledge around art of possibility around Integration of force.cm platform with external system using apex services .One of the main cause has been lack of easy step to step guide so that they can follow and learn these techniques .

The new module Apex Integration Services is a great step forward .I was surprised how challenging these exercises are to crack and it makes sure you understand the concepts well .I strongly recommend cracking this module to gain expertise around integration via apex .

Take your ability to debug and write formulae in force.com to next level

Advanced Admin Trail
Advanced Formulas module is amazing and worth cracking it .It took me an hour being advanced and experienced dev so if you are new this may take more time .You will write some cool validations rules and some complex formulas .After this module i am sure you will be fearless when it comes to writing or debugging some complex formulas .Also note that this is part of new Trail Advanced Admin .

Continue your lightning experience adventure with new modules LEX chatter basics and LEX data management


LEX Data Management

LEX Chatter Basics



Lightning experience is the future of salesforce .With new modules you will continue to understand how to leverage chatter in lightning experience and also understand how to import and export data via dataloader and import wizard provided in the set up menu .

Build an awesome app learning platform basics and also give yourself a chance to win Astronomical Prizes



Battle Station App

This module helps you to learn platform basics and at the end you give yourself a chance to win some cool prizes .So hurry and get this done before 31st dec .The project link is below ,click and get started.The project will teach you how to create apps ,build objects and fields on force.com platform ,write business logic using process builder and workflows ,how to create reports and dashboards and how to use SF1 mobile app to expose the functionality for mobile devices.


Apart from these  Application Lifecycle Management module  is being rewritten to provide more awesome content .

Enjoy Trailhead and dont forget to post your selfie with badges completed on twitter .Also now you can add those badges to your linkedIn profile .

Trailhead Selfie

Apex Testing goodness in spring 16

$
0
0
Spring 16 release notes has been great read .If you have not read ,find some time and do a quick scan to discover some really cool features .

Apex Testing enhancement coming  in spring 16 caught my attention and this blog post covers them in detail .


1)Ability to set createdDate value for test data before Test.startTest()


The below test class demonstrates this new feature 




2)Test Suite


Test suites provide ability to run group of test classes together .On developer console you will find that you have ability to create a New Suite and use New Suite Run to run multiple suites or a single suite .Test Suites functionality is also available through Tooling API .I wont be surprised if this feature is added in some of IDE like Mavensmate or Welkins Suite 




The Suite Manager helps to add or remove Test classes to existing suites or form a new suite or delete existing test suites.

3)Stop a Test Run That’s Failing Miserably

You can now configure test runs to stop executing new tests after a given number of tests fail. You no longer need to waste your time waiting for the results of a run that you’re going to rerun after fixing issues in your org. You can set how many tests can fail in test runs that you execute both in the Developer Console and using the Tooling API.

The Developer Console’s test run configuration panes have a new Settings button. 
To specify how many tests can fail before a test run or test suite run is canceled, click Settings, enter a value for Number of failures allowed, and then click OK. This value applies for all test runs that you execute, until you close the Developer Console or set a new value.

I don't see this yet in spring 16 preview org and i assume it will be delivered .

4)Call Test.startTest() to Reliably Reset Limits in Apex Tests

5)Use @future to Avoid the Dreaded MIXED_DML_OPERATION Error in Apex Tests

To avoid mixed DML we used future method to separate transactions and this caused failures in test class .There are number of workarounds available 

1)We wrapped the code in future method with system.RunAs 
2)Also we  enclosed the code block that makes the future method call within Test.startTest and Test.stopTest statements.

check below link to know the workaround used before this release

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dml_non_mix_sobjects_test_methods.htm

All these workarounds no more needed and test class now does not throw mixed DML

Check the example documented for more details

https://releasenotes.docs.salesforce.com/en-us/spring16/release-notes/rn_apex_tests.htm#rn_apex_tests_limits 

6)Test support for asynchronous WSDL based callouts

There is a neat example on how to approach test case for asynchronous WSDL callout in apex guide 

https://releasenotes.docs.salesforce.com/en-us/spring16/release-notes/rn_apex_tests.htm#rn_apex_tests_limits

Overall there has been great improvement in Testing framework of the apex .Test classes are very important for all apex code on platform .This needs to be seriously taken and great to see SFDC doing its best to enhance testing capabilities .

Lightning Components Tokens

$
0
0
One of the coolest addition to lightning components in Spring 16 release has been Lightning components Tokens .This feature is in developer preview mode and I already see use case for this feature .

Tokens make it easy to ensure that your design is consistent, and even easier to update it as your design evolves.

In this blogpost we will discover how to create these design tokens and how to use it inside the lightning components .I am using spring 16 pre-release org to demonstrate .This feature will be available only after your sandboxes are upgraded to spring 16 release .

Developer console is quickest method to edit and create lightning resources .In developer console you will see lightning tokens 



To create a design token simply click on the lightning Tokens

File | New | Lightning Tokens.

One important thing thats mandatory is to name the lightning Tokens file as "defaultTokens" .This is very important the tokens defined within it are automatically accessible in all Lightning components.

Before we actually start creating lightning Tokens file one thing to note is  Salesforce exposes a set of “base” tokens that we can access in our component style resources apart from custom tokens we create .To do this we will also extend our lightning component tokens from Base tokens .

Here is a sample lightning component tokens file 

Once we have created the file named "defaultTokens" these are directly available in any components in our namespace using small function token() .One just needs to use these in CSS resource of a component bundles.

Here is a sample example component showing how to use design tokens in CSS resource file .


It almost feels like custom labels to me but this is meant for use in the CSS design variables .It makes it easy to keep all design variables in a single resource and any change or update later one can avoid duplication of code and update from one single file .

I am eagerly waiting to see updated lightning components developer guide where salesforce will expose some of the tokens used in the SLDS .

Feel free to spread the word of this upcoming feature but note that salesforce safe harbour applies .

Lightning components - Where all can I have thee...

$
0
0
With Salesforce investing lot on lightning components and I am sure lot of devs in salesforce world have started working with lightning components .

I have also started working on lightning components and below is some cool list on where all currently salesforce allows these components and a small snippet for each showing the interface that lightning component must implement .

Exciting ...Exciting ...Lets start...


  • Add Lightning Components to Salesforce1


 The appHostable interface makes the component available as a custom tab.

All that one has to do is to create a lightning custom tab from salesforce Tabs and add to SF1 Navigation's .




  • Add Lightning Components to Lightning Experience


The interface implemented remains as appHostable .The key here is how we can add this tab to new App launcher 





  • Configure Components for Communities

  • Configure Components for Lightning App Builder

  • Configure Components for Lightning Experience Record Home Pages (PILOT)





















A good example can be one demonstrated by BalaKishan.Please read his articles on lightning .Some great insights into it .

The key here is you have an attribute recordId and sObjectName populated automatically with correctId and API name


<aura:attribute name="sObjectName" type="String"></aura:attribute>
    <!-- Atrribute Defination for Record Id -->
 <aura:attribute name="recordId" type="String"></aura:attribute>

  • Add Lightning Components to Visualforce Pages
This is coolest feature that's been added lately .To add a lightning component to the VF you first define an aura:application that has aura:dependency and extends  ltng:out .

The sample component code The VF code will look like below

I hope you enjoyed this little article :)

Customizing Napili Template Of SFDC For Communities - Community Cloud

$
0
0
Recently I have been busy working with salesforce community cloud platform and I am impressed by the new added features of Spring 16 .

You can watch the Release Readiness webinar for more details on what are added features for community cloud 

Lets talk about something which most of client (Either SI or ISV ) would love to have with the Napili template .The first question that clients ask with Napili is its flexibility to customize and tailor to their specific needs .

The very straight forward questions that people familiar with Napili template ask are as follows 

Can I change the CSS and look and feel ?     
        
   Well yes and No ....The new branding editor you can sparingly use CSS and change look and   feel   and community editor can also help you to some extent to change labels and the color and you can really get closer to what you want .Just note that efforts will be high if we want to change the entire template design.

Will i be able to populate data from custom objects and standard objects and Will i be able to build my own pages ?  

Certainly yes .You can first choose your lightning templates and then build lightning components and drag and drop them .If you understand art of possibilities ,then i am sure its all about working with designer and nailing the UI with mutual consent .    

Can i integrate with third party systems ?Say your knowledge or content is outside SFDC ,Say your idea portal is different ,you want Single Sign on to work as well

The answer is yes and you will build lightning components and use apex to make callouts to external world .I have a sample blog that shows how to build components for communities .

How will I get the context variables of the lightning page so that I can pass those variables to external system to get the data related to that search item ?

A simple example for this use case could be ,I am looking at Topics page of the community and I want to get data from external world related to that topic .

Lets go in detail here on the challenge in hand ...Take a look at one of my stackexchange question i posted lately and got no response nor upvote to appreciate the question 

http://salesforce.stackexchange.com/questions/105627/napili-template-standard-search-event

Ok so context variables in simple terms can be imagined similar to Standard Controller ID ...So the question is how can i identify which Topic I am browsing in my lightning component to fetch matching terms related to that Topic from external world ..The document does horrible and gives no clue .Imagine its Utility for ISV apps .

Lot of ISV partner would like to know the context User is browsing so that their lightning component can give right results in the widget they have on appexchange.

So yes Finally lets come to main aim of this post 

How to find context variables values so that I can build my lightning component based on those ?

Here is the hidden secret (At least no document confirming this)

Every page inside community builder is a lightning page .Check below screenshots ..





























Also every page has some environment variables listed ,


Lets try to capture these and read these via lightning component to see what they actually have 

A sample lightning component code to read the Topic name can be as below



The Design file is most important to capture environment variables

The apex code ::

The last part is configuration when the component is dragged to community builder .Place the exact context variables to derive values from them 

The key again here is to have a design value and use same merge variables as it is used in other variables on the page .

The output is as below when accessed in Topic page



In short the conclusion is ---"One can create design file and use same context variables as other components uses on a lighting page and use the variables to send back to apex to get data related to that context ".

This also answers my own question on stackexchange 


I hope this is a framework for many upcoming appexchange ISV apps and also many communities .Please share this post in case you liked it .

Viewing all 29 articles
Browse latest View live