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
YADAGIRI AVULAYADAGIRI AVULA 

what is the code for Salesforce integration with linkdin?

NagendraNagendra (Salesforce Developers) 
Hi Yadagiri,

Please find the step by step explanation below for integrating salesforce with LinkedIn.
  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.
  • Sign up for a Salesforce and LinkedIn account.
  • Sign into the LinkedIn developer account at: https://developer.linkedin.com/
  • Under your name in the upper-right corner click on ‘API Keys’
  • Click on ‘Add New Application’
  • Fill out the form and click on ‘Add Application’
  • You will get a confirmation page that includes your API Key, Secret Key, OAuth User Token and OAuth User Secret
  • 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.
  • Now everything is setup so that we can write the integration code for LinkedIn in Apex. 
  • 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; } - See more at: https://www.sundoginteractive.com/blog/integrating-salesforce-and-linkedin#sthash.PFpxqajG.dpuf

The scope parameter is important as that specifies what access the caller should have when accessing the LinkedIn API.
  • 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’);
  • 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; - See more at: https://www.sundoginteractive.com/blog/integrating-salesforce-and-linkedin#sthash.PFpxqajG.dpuf
This will return some JSON that will contain your Access Token.
  • 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'); - See more at: https://www.sundoginteractive.com/blog/integrating-salesforce-and-linkedin#sthash.PFpxqajG.dpuf

The linkedInKey can be retrieved by using the search API calls from LinkedIn.
  • 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.

Please mark this post s best answer if it helps.

Best Regards,
Nagendra.P

 
Donny Riyadi Santoso 10Donny Riyadi Santoso 10

Hi Yadigri,
it is not easy to integrate Salesforce to LinkedIn, because LinkedIn is very restrictive on letting anybody integrates with their API.

But you can check this out,

Pipelaunch: LinkedIn Integration for Salesforce
https://appexchange.salesforce.com/listingDetail?listingId=a0N3u00000ONnOcEAL


Cheers