LinkedIn – Salesforce Integration

In this post, I will show how you can connect with LinkedIn from your salesforce org using a small piece of code.

So, Get ready to do another integration with Salesforce.

Before we start playing with the code we need to create a Custom Setting where we will store Access Token and Expiry time so that we could use this while making the callouts.

Setup Custom Setting: –

Go to Setup -> Develop -> Custom Settings -> New -> Name it “LinkedIn Token Info

Custom Setting - LinkedIn

Create a VF page and Controller Class: –

Create an Apex class Name it “LinkedlnoAuthController

Go to Setup -> Develop -> Apex Classes -> New -> 

Next, Create a VF page that will do the Authorization with LinkedIn. Name it “LinkedlnoAuth“.

You will get the complete code from my GitHub Repo. Copy Apex Class and VF page code From Here.

After you created VF page Preview it, Copy the URL and paste somewhere into the notepad++ or any other text editor. URL will be something like below

https://dreamhouse-a-dev-ed–c.ap5.visual.force.com/apex/LinkedlnoAuth

Create an App in LinkedIn: –

Time to create a Connected App into LinkedIn developer account to get the Client Id (Consumer Key)  and Client Secret(Consumer Secret).

Go to LinkedIn Developer Console Create Application. Refer this link to get the complete picture of app configuration. You will get Client Id and Client Secret copy both and store in the text editor.

You LinkedIn app page will look like below

LinkedIn - Application

Make Required Changes into Apex Class: –

1 – Open LinkedlnoAuthController class replace redirect_URI with your VF page preview URI (line #10).

2 – Replace consumerKey with your client Id and consumerSecret with your Client Secret (line #8 and #9).

Now, we are all set to let’s do some testing and see if we have successfully integrated LinkedIn with Salesforce.

Open LinkedlnoAuth VF page and preview it. Click Connect with LinkedIn button, it will open a new screen asking your LinkedIn username and password

Connect with Linkedln

Linked Login

Enter your username and password then sign in Grant permission to Application -> Click Complete Authorization, a success message will show.

Linked Login.png

Now Click on Get Basic Info -> A basic information will show here in PAGE

Basic Info.png

Facing any issue let me know in the comment section.

Happy Coding 🙂 Enjoy Coding 🙂

Sharing is caring 🙂

 

 

6 thoughts on “LinkedIn – Salesforce Integration

  1. Hi ,
    I do all the steps mentioned above . But at last while Complete Authorization i got the below error and and not able to proceed further

    Errors

    Access Code: Access Code: data value too large: AQUcaxhKtzEyVEmhoDFDuepjsMUfGwM1T0OCMUhT7DWucf1pZBtno5avpt-zVJIyLlCW_VP2nrY9YBQoEjCbR_HOghcaqkN1TGTXik1XuLSImaQUOJAeaeJ1rPMnOILhZ9QPF3HYaYmYtfuv5HYNDmu40MJGBi-6lbu2kjU58TimJRXQiUl4PcfB8dqgFmLOZVqKB6hKvRo8xgAJH2Ulqm7Ls-H4MQMb4n656pmhihOVO340Wsk3og2Eh5gSTWhbAXFvme5rbVKGBOFuJ4PfqyFtMHlYZwDiK92sfZ3nHt8H5kQeOV8f5nouw-BmcUDm4zAsUzbs5E6_6gsBEKLY990ZIT0ENA (max length=255)
    Unexpected Error while communicating with LinkedIn API. Status OK and Status Code 200
    CONFIRM
    Success:
    Congrattzzzzz….. You have done successfull Integration with Linkedln

    Error:
    Unexpected Error while communicating with LinkedIn API. Status Bad Request and Status Code 400

    1. Hi Raheshwar,

      The Error is because the value of the access token length is 255 chars. To avoid the Error Please use Custom metadata OR custom instead of Custom Setting to store the access and refresh token and make the changes in the code accordingly.

      1. Hi Amit,
        I replaced the Access_Token__c with Access_Token_1__c and Access_Token_2__c. On authentication I split the access token into two segments and stored the segments into the two attributes. On retrieval, I retrieved the token segments from the attributes and concatenated them. Just seemed easier than using metadata and having to do SOQL calls.
        Cheers,
        Richard

Leave a Reply

Your email address will not be published. Required fields are marked *