Friday, August 15, 2014

Calling APEX Rest service using Postman

This post explains the setup of Postman REST Client.  Postman REST client is an add-on for chrome that can connect to Salesforce using OAUTH 2.0 password flow.  Using this method, you can get the access token to call your APEX rest service.  

This topic assumes that you already have Postman REST client.  In case you don't have Postman REST Client, you can download from Chrome Store


Setting up OAUTH

Open Postman and click on new Collection to create a new collection.  Then enter the collection name as shown in below




Click on Create to create a new collection.  This will create a new collection

Now, we are ready to get the access token from Salesforce using OAUTH.  Enter the Authentication URL to salesforce under Normal Settings of the Postman.  For Sandbox the Authentication URL is https://test.salesforce.com/services/oauth2/token and for production it is https://login.salesforce.com/services/oauth2/token.

Then select form-data is a method of POST to salesforce.  The following key value paris are necessary to post the authentication information to Salesforce.  

  •  grant_type=password
  • client_id=<clientId>
  • client_secret=<clientSecret>
  • username=<username>
  • password=<password>
The values for <clientId> and <clientSecret> need to be configured as an OAUTH application in Salesforce.  For more information on the setting up app access, refer to sale force documentation here..  Save the script.  You have the script read.  Now, add the script to the collection you have just created, by selecting "Add to Collection" button.



To get the access token, click on the "Send" button to get the send the authentication request.  If the user name, password, client id, client secret is correct, salesforce will return a JSON structure that contains access token.

You can now use this access token in the Request header to process calls in Salesforce.



  • Crete a new service by cloning the existing OAUTH service. 
  •  Change the URL to your apex service.  The format of the URL will be:  <instance_name>/services/apexrest/<servicename>/<version>  In this example we will us helloWorld Service.  so the instance url will be <instance_name>/services/apexrest/helloWorld/
  • Create a new Header Authorization parameter that has the access_token from the previous step.
  • Set the Content-Type as 'application/json'
  • Enter the JSON message in the Body to be submitted to Salesforce


The sample call to helloWorld Service in Salesforce is shown in screen capture below.  This service uses HTTP POST to post the message and the service responds back with the helloWorld in the respective language.




Now you can test your web services by click of a button.  Happy development!

Thursday, June 13, 2013

Salesforce Communities Replaces Portals


Salesforce recently announced that Salesforce Communities will be replace Customer Portal and Partner Portal.  This would be great for the customers who currently can't get all the juice out of portals.  For some-time now (4 months), I have been playing around and using communities during the pilot and think that Salesforce finally found a way to make Portals as a true "social" platform for Salesforce's users to communicate with its customers and partners.  I believe there are several advantages for Salesforce communities to switch to the communities if they are already using Customer or Partner Portals. The current customers can readily take advantages for 
  • Chatter:  I have seen most of the times when customers hear about Customer or Partner portals, they ask if Chatter can be used.  With Customer/Partner Communities, this feature is available OOTB
  • Use of Permission Sets:  If you have used Permission Sets in Salesforce, you would love this features.  You can use profiles and permission sets to configure access to Salesforce objects and resources
  • Better Branding:  The branding of communities goes all the way from look and feel to email templates and also chatter.  Currently branding of portals (unless some serious customizations) is awful and needs some serious TLC. With communities, the look is somewhat similar to internal uses see and als the branding can really customized easily.  This will make the interface consistant with rest of Salesforce
  • Better Login & forgot password functionality:  No need to configure Sites which will make the login more simpler.  The forgot password functionality will be similar to how currently Salesforce.com sends out an email to uses to reset password.  In the customer portal, the email was sent out temporary password.  With Communities, this security hole is fixed, which means also reduces the need to write custom password reset functionality if you are too serious about sending user name and temp. password in the same email.
I'll add more features and "how-to" in future blogs.

Thursday, May 16, 2013

Version problems with Salesforce Lists and Ext.Js

Have you ever wondered, once you use javascript in your left side bar in Salesforce, your list pages just hang and see the ever ubiquitous, spinning wheel?
Well, today I have encountered this as we have been rolling out are beta release of a Appexchange product.

The issue is that when you are using Ext.JS for any development and JavaScripting, make sure that those are compatible with Salesforce Ext.JS libraries.  Otherwise, you will run into JavaScript version libary problems and Salesforce Lists will just not work.  Salesforce Lists usings Ext.JS libraries to pull the lists and this causes all the trouble

Monday, May 13, 2013

Leading Big Vision from Heart

I've borrowed this title Stanford University's Leadership series podcast from Justin Rosenstein  of Asana.  Everyone should hear this podcast to see how a small startup is able to lead a change in organizations to share resources and become more collaborative in solving complex problems.

We so often forget in daily pony-and-dog-show by leaders that how important it is for the employees to focus on vision of the organization.  It is primary job of the leaders to ensure that every decision taken by them are small steps is towards that vision.  This will enable employees who serve the customers understand how they can forward that greater vision.  While many may see this is all "text book" speak and does not happen in organizations  I would call as BS.  I had the privilege of working with some true leaders in their capacity who have followed the principle of leading through big vision and I'm very grateful for them for mentoring me.

The basic responsibility of a leader is to make sure, they let the employees understand the goal and purpose.  The leader is the captain of the ship. An organization may have performed well in the past and in near term, but without a goal and purpose, it is like a drunk captain who is enjoying the catch (s)he just had caught and not worried of the storms in the horizon.   The employees too will ignore what is in the horizon and just enjoy the party on-board, and think who caution on the impending storm are just people who don't understand how to party.  In these cases, the captain of the ship who does not take any responsibility and is happy to maintain the status-quo only to see in few years, they will be like 100s of organization buried by the storm on "change".

In this every changing world, technology is enabling competition a small 5 people company to compete with a large corporate.  The same technology if not adopted quickly is risking companies(For Example BMC Software) to go out of business is a telling tale of how leaders can really screw-up organization and employees from having a leaner, open and collaborative environments.


Sunday, April 14, 2013

Google's changing focus

Recently Google announced that it is pulling the plug on Google Reader on July 1st 2013.  It was a weird feeling I was reading about this in Google Reader itself.  I've been using Google Reader since past 4 years regularly.  I feel this is one tool that Google has produced that is simple, easy to use and meets the needs.

From Google's perspective I totally get it why they want to go away from Google Reader.

  • It is not an effective advertising revenue generator
  • Is not as "Social" as Google+
  • Standalone product and does not integrate with other Google's ecosystem 
  • Does not serve Google's enterprise push:  Google's focus is not on its enterprise than regular common users as its add revenue has reached a crest

Monday, February 4, 2013

Apex Mobile User License Explained

Last week, I was looking at the org. license details of one of our customers who wanted to see if they can use the mobile license.  They did not have mobile licenses or purchased any.  While looking Company Profile section of the Setup, I found that they had "Apex Mobile User" Licenses.  As this does not explain the difference between "Apex Mobile User" and "Salesforce Mobile" licenses, I contacted Salesforce and got a very clear and conscience explanation of these different type licenses

Apparently I was informed by SFDC that "Apex Mobile User" and "Salesforce Mobile" licenses are the one and same.  Apex Mobile User License have full support of mobile features of Salesforce.  This license can work on Visualforce, Page Layouts, Standard or Custom object of Salesforce.  Each users will have to enabled explicitly to enable them for mobile devices.

So, now that the customer has Apex Mobile licenses, their team can leverage these features.


Sunday, September 2, 2012

Working with JPlayer and Visualforce

I recently came across a need to have audio on a Visualforce pages.  While embedding a flash based audio would be easy enough to do, it would not solve the purpose as flash is not universal and compatible across.  I started off with HTML5 audio tag.

<audio> tag makes the life of a developer easy.  I tested in Firefox, Chrome and Safari and it was working grand.  Now comes the bummer IE9.  Even though it is written everywhere that IE9 supports audio tag, there is a catch.  IE9 supports only the events of Audio tag but no direct support as other browsers provide.  Moreover the older version of IE (IE8 and IE7) do not support so in a way there is no way you can use audio tag yet considering IE is still one the most users browsers in the market.

Other than the standard browser support, the VF page also had to work on mobile platforms.  jPlayer is on of the most widely used jQuery plugin that addresses this very issue of compatiblity at the same time providing a very nice UI elements to manipulate

Here is the visual force example of using jPlayer plugin with jQuery to make the pages audio enabled.  jPlayer provides nice documentation for events and properties of the plugin



1:  <!DOCTYPE html>  
2:  <apex:page showHeader="false" standardStylesheets="false" >  
3:    <head>  
4:    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />  
5:    <apex:includeScript value="{!$Resource.jQuery14}" />  
6:    <apex:includeScript value="{!URLFOR($Resource.jPlayer,'jPlayer/js/jquery.jplayer.min.js')}"></apex:includeScript>  
7:    <apex:stylesheet value="{!URLFOR($Resource.jPlayer,'jPlayer/skin/blue.monday/jplayer.blue.monday.css')}"></apex:stylesheet>  
8:    <script type="text/javascript">  
9:      $(document).ready(function(){  
10:        alert(this.internal.flash.id);  
11:        $("#jquery_jplayer_1").jPlayer({  
12:          ready: function () {  
13:            $(this).jPlayer("setMedia", {  
14:              mp3:"{!$Resource.Q00000001mp3}",  
15:              oga:"{!$Resource.Q00000001ogg}"  
16:            }).jPlayer("play");  
17:          },  
18:          swfPath: "{!URLFOR($Resource.jPlayer,'jPlayer/js')}",  
19:          supplied: "mp3, oga",  
20:          solution: "flash, html",  
21:          wmode: "window"  
22:        });  
23:      });  
24:    </script>  
25:    </head>  
26:    <body>  
27:      <div id="jquery_jplayer_1" class="jp-jplayer"></div>  
28:      <div id="jp_container_1" class="jp-audio">  
29:        <div class="jp-type-single">  
30:          <div class="jp-gui jp-interface">  
31:            <ul class="jp-controls">  
32:              <li><a href="javascript:;" class="jp-play" tabindex="1">play</a></li>  
33:              <li><a href="javascript:;" class="jp-pause" tabindex="1">pause</a></li>  
34:              <li><a href="javascript:;" class="jp-stop" tabindex="1">stop</a></li>  
35:              <li><a href="javascript:;" class="jp-mute" tabindex="1" title="mute">mute</a></li>  
36:              <li><a href="javascript:;" class="jp-unmute" tabindex="1" title="unmute">unmute</a></li>  
37:              <li><a href="javascript:;" class="jp-volume-max" tabindex="1" title="max volume">max volume</a></li>  
38:            </ul>  
39:            <div class="jp-progress">  
40:              <div class="jp-seek-bar">  
41:                <div class="jp-play-bar"></div>  
42:              </div>  
43:            </div>  
44:            <div class="jp-volume-bar">  
45:              <div class="jp-volume-bar-value"></div>  
46:            </div>  
47:            <div class="jp-time-holder">  
48:              <div class="jp-current-time"></div>  
49:              <div class="jp-duration"></div>  
50:              <ul class="jp-toggles">  
51:                <li><a href="javascript:;" class="jp-repeat" tabindex="1" title="repeat">repeat</a></li>  
52:                <li><a href="javascript:;" class="jp-repeat-off" tabindex="1" title="repeat off">repeat off</a></li>  
53:              </ul>  
54:            </div>  
55:          </div>  
56:          <div class="jp-title">  
57:            <ul>  
58:              <li>Cro Magnon Man</li>  
59:            </ul>  
60:          </div>  
61:          <div class="jp-no-solution">  
62:            <span>Update Required</span>  
63:            To play the media you will need to either update your browser to a recent version or update your <a href="http://get.adobe.com/flashplayer/" target="_blank">Flash plugin</a>.  
64:          </div>  
65:        </div>  
66:      </div>  
67:    </body>  
68:  </apex:page>  

Monday, August 20, 2012

Working with 10 KB restriction with Portal Header and Footer

One of the restrictions (out of hundreds!) the Force.com platform places on Portal (Customer/Partner) is the footer and header size cannot be more than 10 KB.  While this may help to increase the speed at the same time, it inhibits the custom long headers and footers that some customers have.

One of the work arounds this issue is to minify the HTML, JavaScript and CSS that is there in the headers.  It really reduced the size of the Headers and Footers.  Will Peavy created this beautiful page to  minify HTML and all of its content.  The note of caution is see that the jQuery/JavaScript is well formed otherwise it becomes very difficult to debug.

Thursday, August 16, 2012

Authorization Issue with Sites on Force.com

One of the most annoying things in any development is authorization errors.  The problem multiplies itself when there is no stack trace on where the authorization errors are coming.  Last couple of days we ran into a bunch of Unauthorized errors while accessing, Visualforce pages on public sites.

Today finally was able find the root cause.  The issue was one of the columns referred in the SOQL belongs to the parent object and the object did not have access

Since, Salesforce does not display any error or where exactly this issue is here are few ways I think would help you to quickly identify the root cause


  • Enable debugging for the sites users
  • Check the debug logs and look for the log just before the authorization error
  • Go to the bottom of the log and trace back the code
    • One of the easier ways to find the issue is to add debug statements at different points where you think the most probable cause of failure could be
  • Check of the statement that last executed
  • Verify if the statement is the last statement in the method (apex code)
  • If you don't see that it is the last statement, then the failure just occurred at the statement
  • If the issue is with the SOQL, see that the columns being queried in the SOQL have access to the Force.com sites

Hopefully these steps will expedite the authorization issues you would encounter.  Let me know if you  found variations of this issue

Tuesday, August 14, 2012

Static resources on Force.com

One of the interesting things I ran into today while making customer portal pages look like another external web-site using static resources


  •  use timestamp in the resource url
    • For example if you are using static resources in a zip file (one of the best practices for maintaining static resources) use timestamp in the URL  /resources/id/timestamp/<filepath>
If you don't use this method to access, you may see a delay in the resources getting reflected by Salesforce Content Delivery network.

The other idea may be to use Amazon CDN which would make the page load quicker

Sunday, August 12, 2012

One of my best Bike Rides


This Saturday Prthika and I were able stretch a bit to do a 26 mile bike ride along W & OD trail.  It was a refresher.  I've been doing 10-20 miles but this one was special.





Find more Bike Ride in Tysons Corner, VA

Sunday, February 26, 2012

Moving my website to Node.js, CoffeeScript and backbone.js

Earlier this week and sometime yesterday, I've been trying to get out of the day-to-day choro get some fresh air from the world of new frameworks and languages


Stumbled upon CoffeScript and Backbone.js.  As far as I can read, these offers great future in removing the clunkiness from programming languages and are truly grounded in DRY principles.  I'll plan to move my site on top these frameworks/languages and see how it goes. 

Self-Service portal isn’t available for new organizations.

In Spring'12 release notes, Self-Service portal is not available for new organizations.  I'm not sure how many organizations are using self-service portal.  But it is one of the least customizable features on Salesforce.com.  


What does this mean to the organizations?


1) The org. that were planning to use self-service portal can no longer use this free service from salesforce.  
2) Existing orgs. would eventually have to move to a chatter based solution if they are already using self-service or some kind of custom development on customer portal


One undesired thing from this outcome is that, Salesforce is effectively removing the freebie that it offered to its customers to create cases.  Web-to-case is there but it is truly not a self-service solution.  This also means driving users to use more chatter and in the end chatter licenses have to be purchased!


Sunday, January 22, 2012

Environment specific variables in SalesForce

If you are developing web-service callouts in development or sandbox and moving them to production, you have to manually change the properties of the out-bound webservices.  For example, you are developing a callout that updates the customer information to an external system when a new customer record is created in SalesForce in Sandbox.  After completing the testing of the callout, you would want to move your apex code to production org.  But, the end point, authentication details of the outbound service will be different than the one in test environments. 

Unfortunately, SalesForce doesn't provide the flexibility of configuration/property files that Java provides.  Luckily SalesForce now provides Custom Label functionality that can be used for this purpose.  
I normally define the endpoints, authentication details as custom labels in sandbox and production orgs.  The advantage is, 
  • the apex classes need not change from sandbox to production.  
  • The test cases run perfectly fine in sandbox and production orgs.  
  • When there is a change in environment specific property value, you need not create a change-set or migrate your code.  
  • Better Apex code development


To create custom labels
Setup->Create->Custom Labels

There are other way of externalizing the properties 

  • Create Properties__C object and store the properties.  The disadvantage of this approach is you are maintaining an object for properties and issuing SOQL queries to retrieve the properties.  
  • Using URLRewrite:  While this solves the purpose like the one mentioned above.  It involves find the parsing various formats of SalesForce's representation of the URLs, i.e.. different urls for internal users, portal users and sites users and you have to understand them
  • Page References:  Using page reference to get the url is limited by developing VF pages and would not address the purpose of this discussion
  • Get Organization ID:  Getting the org. id will also solve the purpose and you can determine based on the org. id which property to use.  But this can lead to issues when you have more than 2 orgs and also multiple outbound web-service environments

Monday, January 2, 2012

UMLet for UML diagrams

Last week, I was searching a free light weight UML software that I can use for doing some UML stuff for a design specification.  I found UMLet to be a cool tool that is easy to develop Activity, Component and Use Case Diagrams.  I can now do design and uml within minutes this tool.  Checkout at www.umlet.com.  


BTW, did I mention how painless it is use in eclipse too!!

Happy New Year 2012

Wishing you a very happy and prosperous 2012 ahead.  I got a chance to lay my hands on one of the best books I've read ever.  The title of the book is "I moved your cheese" by Deepak Malhotra.  This is a must read book if you have already read "Who moved my cheese" by Spencer Johnson.  

Deepak Malhotra brilliantly put forth the need to question the change which Spencer Johnson doesn't cover in the book.  I've loved reading WMMC in the last 9 years and everytime I read, find something new.  Now, I've IMYC an addition to WMMC. 

The best part I liked about the IMYC; it was short, to the point and the author did not dwell into what should the best steps to question change (Maze and Cheese).  Instead he used Max, Zed and Big to come up with their answers by looking at the maze.  Deepak Malhotra asked a series of questions that the reader can answer from their experiences and thoughts.  I would recommend as is a must read for every professional

Wednesday, December 28, 2011

Multiple Users for a contact in SalesForce Customer Portal

This article discusses about
  • Creating Multiple Users for the same contact in Customer Portal

While there is already an article on SalesForce wiki about creating a customer portal user, it doesn't address my case of creating users through a trigger instead of the visual force page.  Also, the user creation is not dependent on the contact creation but creation of a contact's child record.  Before I jump into the nuts and bolts of the things, let me give a background.  (Here I assume that you have an understanding of how single sign-on works.  SalesForce has a very good article describing single sign-on process in salesforce.  This article only deals with traditional SAML 2.0 federation authentication as salesforce supports only this type of authentication of Customer Portals.

Background
Recently, I came across an issue related to the single sign-on integration with salesforce.  The existing identity provider system identifies users by the subscription ids.  For example, if John Smith has three subscriptions (S100, S200 and S300), then John is identified by the IDP as a three users who have access to the system.  In SalesForce, we have created Subscriptions of Contact.  So, subscription details (start date, end date, payment, active/inactive, etc..) is the child of the Contact.  That means that we have cannot use subscription IDs to create users; as SFDC only allows one user per contact.  You cannot create multiple portal users for the same contact




Implementation
This implementation only addresses the test case and trigger that was developed as a proof of concept to show how we cannot create multiple portal users for the same contact


First we account and contact in the test case




Monday, November 28, 2011

Evaluating IaaS for Small and Medium Size companies Part 1

I've been spending some part of my last week evaluating Infrastructure as a Service companies to move my company servers onto the cloud.  Being a cloud services company it makes easier for us to move the infrastructure to the cloud.  There are several advantages to move the servers from in-house or remote management to the cloud.


1.  Less hassels managing the hardware
2.  Paying for the administrators to manage hardware
3.  Removes hassels of dealing with the ISP
4.  That is not my companies core competencies
5.  I pay only for the resources that I use and most of the times, I'm not utilizing resources 100%
6.  Makes the company more green and saves green bucks


I've used Gartner's magic quadrant to evaluate the Service provides.  I narrowed down to three for the ease of evaluation and also access to the service companies


1.  RackSpace
2.  Amazon Web Services EC2
3.  GoGrid


Total Cost:
I think Amazon has one of the best self-help documentations available among the IaaS.  The other thing I like about Amazon is their price structure.  It is standard and easier to understand and predict.  Compare these with anyone in this group and you would get a reply, talk to account manager or how about some free trail.      This just leads me to believe that I don't know the exact cost in next one, two or three years that I would incur when I'm moving my server infrastructure on your backbone.  I don't mean to say that this drives me away from other three wonderos.  But price is one of the drivers of moving from in-house to cloud.  Isn't it?


VPN, Private and Public Clouds:
To my surprise, Amazon doesn't have a good VPN, Private and Public Cloud services.  GoGrid and RackSpace both offer these services.  May be because, Amazon thinks that its too much of an hassel and also their customer base isn't asking them a lot yet.  Honestly for me this is a "good to have" currently, because we don't have plan to be in a mix of clouds.  Being a small company, it doesn't make sense to be working on multiple cloud offerings.  So for me this is a good to have feature so that in future when I need it I can make use of them


Managed and Self-managed cloud:
Since being a small company and servers not being a core competency, I was looking for a managed or some kind semi-managed.  GoGrid and Rackspace scored brownies here and Amazon was all about self-managed infrastructure.  So if I wanted to move to Amazon, I'd to spend some part of my time maintaing the infrastructure


Customer Service:
Customer Service from Amazon perspective is as good as its costs are.  Also, I think from the stand point of moving from moving ones infrastructure onto cloud, there is little an IaaS vendor would offer interms of Strategy.  The uptime and any backups are critical and all three vendors do a great job in uptime and guarantee. GoGrid offers 100% uptime.  


Licensing and Software Package:
I think in all Amazon had the best package in terms of licensing.  You can use ms-sql server licenses that you already have purchased to use them in AMIs.  Also I think there is some documentation that is involved between you and Microsoft regarding this.  Also, I've heard that GoGrid and RackSpace offer similar offerings but not tested them.  Also, I don't have clear picture on much money additional software costs on these machies compared to AWS AMIs.


Speed and Latency:
Amazon is the best in the industry interms of latency.  In east coast they have servers in Virginia (did I mention in Herndon?) which is great for someone is lives at a stone throw:).  Anyways, they have pretty good DCs located across the globe.  I think GoGrid and RackSpace have pretty good reach in North America.  But being a small business, currently, I am not looking for a reach across the globe.  So for me, all three are tie


Thought Leaders:
Amazon has been one of the key drivers in this space and have wide array of offerings.  RackSpace is surely an industry mover for IaaS and managed hosting.  GoGrid is a niche player for IaaS.  Again all these analysis is based on my evaluation of the three offerings and Gartner's magic quadrant.