function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
shalushalu 

LinkedIn <> Salesforce Integration

I have downloaded LinkedIn app already - just need somebody to complete integration so I can see on Accounts + Contacts pages. 
I have LinkedIn Sales Navigator account.


for client need / i want use case of this and can anyone explain about this .

 can anyone help for this requirement ?

thanks....
 
NagendraNagendra (Salesforce Developers) 
Hi Shalu,

Salesforce and LinkedIn already have some integrations that can be leveraged from the AppExchange at Salesforce.

1) LinkedIn Sales Navigator for Salesforce can be found here. This app costs users 39 a month and is created by LinkedIn itself.
2) Ebsta for LinkedIn can be found here. This one seems to have a cost only if you want to update the Salesforce data within LinkedIn. This app appears to keep the user in LinkedIn and then will query Salesforce to see if there is a match.
3) Ecquire - Add Contacts from LinkedIn with One Click can be found here. This one costs 19 per user per month and the integration also works from the LinkedIn side. The user clicks a button in LinkedIn and the data is sent to Salesforce.
4) Redkite Connector - This one is no longer available because of changes to the API with LinkedIn, but it seemed to have been a very popular AppExchange download for a while.

So these are just a few of the off-the-shelf tools that are trying to integrate Salesforce and LinkedIn for you. But what if you want to do something custom? I will walk you through a few steps to get you started.

1) Sign up for a Salesforce and LinkedIn account.
2) Sign into the LinkedIn developer account at: https://developer.linkedin.com/
3) Under your name in the upper-right corner click on ‘API Keys’
4) Click on ‘Add New Application’
5) Fill out the form and click on ‘Add Application’
6) You will get a confirmation page that includes your API Key, Secret Key, OAuth User Token and OAuth User Secret
7) One thing to note right away is that this basic LinkedIn application has limits on it for the number of calls. If you click on the ‘VIEW API USAGE’ link you will see your daily limits.
8) Now everything is setup so that we can write the integration code for LinkedIn in Apex. 
9) The first step in the OAuth sequence is to call a LinkedIn endpoint passing your API Key and the redirect_uri among other things. Basically, you are sending the user to LinkedIn where the user will login and then grant access to your LinkedIn application. LinkedIn will then pass back an Authorization Code on the query string to the URL that was passed in the ‘redirect_uri’ parameter. Here is some simple Apex code to make this call.

public PageReference newAuthorizationCode(){
 	string APIKey = getMyAPIKey();  //Store the API key in a custom setting
 	/*
 		https://www.linkedin.com/uas/oauth2/authorization?response_type=code
                                           &client_id=YOUR_API_KEY
                                           &scope=SCOPE
                                           &state=STATE
                                           &redirect_uri=YOUR_REDIRECT_URI
        */
        
        string state = 'Anything you want returned to you'; //This state value will be passed back on redirect_uri
        string myEndPoint = '';
        string redirectPage = 'https://na6.salesforce.com/apex/LinkedInReturn';
        string scope = 'r_basicprofile r_fullprofile r_emailaddress r_network r_contactinfo rw_nus rw_groups w_messages';
        redirectPage = EncodingUtil.urlEncode(redirectPage, 'UTF-8');
        scope = EncodingUtil.urlEncode(scope, 'UTF-8');
        state = EncodingUtil.urlEncode(state, 'UTF-8');
        myEndPoint = 'https://www.linkedin.com/uas/oauth2/authorization?';
        myEndPoint += 'response_type=code';
        myEndPoint += '&client_id=' + APIKey;
        myEndPoint += '&scope=' + scope;
        myEndPoint += '&state=' + state;
        myEndPoint += '&redirect_uri=' + redirectPage;
        
        PageReference pr = new PageReference(myEndPoint);
	return pr;
 }

The scope parameter is important as that specifies what access the caller should have when accessing the LinkedIn API.

10) Now you need to add code to the ‘LinkedInReturn’ Visualforce page in order to get the Authorization Code off of the URL. The Authorization Code will come back in the ‘code’ query string so you will be able to get it like this in Apex:

myoAuthCode = ApexPages.CurrentPage().getParameters().get(‘code’);

11) Now that you have the Authorization Code you get call LinkedIn to get an Access Token. You must POST to an endPoint that is built like this…

LinkedInEndPoint = 'https://www.linkedin.com/uas/oauth2/accessToken?' +
        	'grant_type=authorization_code' +
        	'&code=' + oAuthCode +
        	'&redirect_uri=' + redirectPage +
        	'&client_id=' + APIKey +
        	'&client_secret=' + ClientSecret;

This will return some JSON that will contain your Access Token.

12) With this Access Token you can now make your calls to LinkedIn to get the data that you want. For example, passing this type of data to the v1/people/id endpoint will return JSON data that has information about that specific user:

Http h = new Http();
HttpRequest req = new HttpRequest();
string accessToken = getAccessToken();  //This is the Access Token which we retrieved earlier.  Maybe store it in a custom setting.
req.setEndpoint('https://api.linkedin.com/v1/people/id=' + linkedInKey + 
        		':(first-name,last-name,headline,location,distance,num-connections,picture-url,positions,public-profile-url)?format=json&oauth2_access_token=' + accessToken);
req.setMethod('GET');

The linkedInKey can be retrieved by using the search API calls from LinkedIn.

13) At some point this Access Token will expire so you should try to refresh it before that happens. If you do not do this, then you will have to repeat all of the steps above to get a new Access Token.

I hope this gives you a jump-start in building your own integration with LinkedIn.

If there is an integration that you would like to see me blog about please let me know. I would love to dive into APIs like Twitter, Facebook or Instagram in future blogs.

For more information please refer to below link.

Hope this helps.

Kindly mark this as solved if the reply was helpful.

Thanks,
Nagendra
shalushalu
 Hi Nagendra,
 can you explain above requirement ?
use case / explain about it.....