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“
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
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
Enter your username and password then sign in Grant permission to Application -> Click Complete Authorization, a success message will show.
Now Click on Get Basic Info -> A basic information will show here in PAGE
Facing any issue let me know in the comment section.
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
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.
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
Seems to be a great Workaround 🙂
Hi Amit,
Nice piece of work!
Thought you might like to mention this step in your excellent user guide.
Unauthorize endpoint: An Administer must go to Setup -> Administer -> Security Control -> Remote Site Setting and add https://www.linkedin.com/oauth/v2/accessToken Endpoint
Thanks and regards,
Richard.
Sure. I will add the same thanks for pointing our.
Hi Amit, first of all thank you for your work and for making this tutorial and the youtube video.
I would like to know if you know what changes should be made to the controller in order to make the integration with Linkedin using their v2 API (the version 1 of the API cannot be used anymore).
Thanks in advanced!
Hi,
Here is the updated code but I will also suggest you to Go with the API.
LinkedIn API V2
Thanks,
SFDCPanther
Hello Amit
Linkedin integration Working greate. But I need some help with that. I will create the contact of Linkedin connection. if you have any solution for this. I have tried but it will not work.
Hey Ankit,
For this, you need a company application and once your application is approved you can use connection API to get all the details. In a Normal application, you can not fetch connections.
Thanks & Regards,
SFDCPanther
Hi Amit,
My Linkedin Integration is Working. But when it comes to Post Sharing, it is showing “Unexpected Error while communicating with LinkedIn API. Status Unprocessable Entity and Status Code 422” this error. I have used advanced v2 code .Please help me out. Thanks in advance
Hi Swetha,
LinkedIn has changed their API recently. Please check the document once.