LinkedIn – Salesforce Integration

Hello All, I am back with another Integration post and 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 Object: –

Go to Setup -> Create -> Objects -> New -> Name it “LinkedIn Information

LinkedIn Informations

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 🙂

70 thoughts on “LinkedIn – Salesforce Integration

  1. Sivakumar January 11, 2020 / 8:09 pm

    Hi Amit,

    I have requirement to integrate Linked Campaign Manager to full the campaign budgets ,impression information .

    Could you please let me know how can we full the data using rest api

    Like

    • Amit Singh January 12, 2020 / 7:51 am

      Hey,

      Have you tried reading the LinkedIn API document for the same?

      Also, in the developed LinkedIn application this can not be achieved. You need to upgrade your application for which they will ask company information and after approving you can work on the detail.

      Like

  2. Jawed Khan December 13, 2019 / 1:26 pm

    I am getting that error when try to share post on linkedin where as i am getting my basic information currectly :

    Unexpected Error while communicating with LinkedIn API. Status Unauthorized and Status Code 401

    Like

    • Amit Singh January 2, 2020 / 9:50 am

      Check the debug log and you will get the complete Error about the same. And then try to resolve the error

      Like

  3. Jawed Khan December 13, 2019 / 1:23 pm

    I am getting that value while fetching basic information. please suggest how to remove localized parts:

    {“localizedLastName”:”khan”,”lastName”:{“localized”:{“en_US”:”khan”},”preferredLocale”:{“country”:”US”,”language”:”en”}},”firstName”:{“localized”:{“en_US”:”jawed”},”preferredLocale”:{“country”:”US”,”language”:”en”}},”profilePicture”:{“displayImage”:”urn:li:digitalmediaAsset:C5103AQEhlpTDHOzjXg”},”id”:”gdwUOtYOGv”,”localizedFirstName”:”jawed”}

    Like

    • Amit Singh January 2, 2020 / 9:51 am

      Hey, This a Json response you can easily parse the response and then replace the localized with blank string.

      Like

  4. Jawed December 13, 2019 / 1:18 pm

    I am getting that result while fettching basic information :

    {“localizedLastName”:”khan”,”lastName”:{“localized”:{“en_US”:”khan”},”preferredLocale”:{“country”:”US”,”language”:”en”}},”firstName”:{“localized”:{“en_US”:”jawed”},”preferredLocale”:{“country”:”US”,”language”:”en”}},”profilePicture”:{“displayImage”:”urn:li:digitalmediaAsset:C5103AQEhlpTDHOzjXg”},”id”:”gdwUOtYOGv”,”localizedFirstName”:”jawed”}

    Like

  5. Shreya Swaroop December 13, 2019 / 6:05 am

    The fetchbasicinfo method is not working for me.

    Like

  6. ankit sharma November 5, 2019 / 2:00 pm

    Integration With Linkdlin

    LinkedIn – Salesforce Integration

    Hello Amit thank you for your help this blog very helpful for me.

    i need one help i get all connection in salesforce as contact. Please provide me any solution

    Like

    • Amit Singh January 2, 2020 / 9:53 am

      Hey, Sorry for the late response but to get all the connection you need to upgrade your LinkedIn application access and the access can only be granted for companies only it’s not for practice purpose.

      Like

  7. Karishma Gurjar August 1, 2019 / 6:50 pm

    Hi Amit,

    I need to get information from Linkedln like First Name, Last Name, Email (in short whatever is public information available in Linkedln) and show this on Salesforce after clicking “Get Basic Information” button. Could you please help me, what changes required to your code as I am gettinf error now after clicking “Get Basic Information” button– “Unexpected Error while communicating with LinkedIn API. Status Gone and Status Code 410”

    Liked by 1 person

  8. ghodasara divya May 1, 2019 / 11:20 am

    plz, share a link of updated code.

    Like

    • Amit Singh May 2, 2019 / 7:18 am
      Here is the Link to Updated code. Make changes according to your Application .gist table { margin-bottom: 0; } This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters public class LinkedlnoAuthController{ public Boolean isCode { get; set; } public String authCodeFromURL { get; set; } public List<LinkedIn_Information__c> linkedlnInfoList { get; set; } public String BasicInfo { get; set; } public String urlToSharedPost { get; set; } public String sharedInformation { get; set; } public Final String consumerKey = 'YOUR_CONSUMER_KEY'; public Final String consumerSecret ='YOUR_CONSUMER_SECRET'; public Final String redirect_URI = 'YOUR_CALLBACK_URL'; public String linkedln_Scope = 'r_basicprofile%20r_emailaddress%20r_liteprofile%20w_share%20rw_company_admin%20w_member_social'; public Final String linkedln_AuthUrl = 'https://www.linkedin.com/oauth/v2/authorization?&#39;; public Final String accessToken_Endpoint = 'https://www.linkedin.com/oauth/v2/accessToken&#39;; public LinkedlnoAuthController(){ authCodeFromURL = ApexPages.currentPage().getParameters().get('code'); if(authCodeFromURL == null || authCodeFromURL == '') isCode = true; else isCode = false; linkedlnInfoList = [Select Id, Name,Access_Token__c,Expires_In_Seconds__c From LinkedIn_Information__c Where Name='LinkedlnInfo']; } public PageReference doGetAuthorizationCode(){ String requestoAuthURL = linkedln_AuthUrl + 'response_type=code&client_id='+consumerKey+'&redirect_uri='+redirect_URI+ '&state=12345567dggd&scope='+linkedln_Scope; System.debug(' #### requestoAuthURL '+requestoAuthURL); PageReference pageRef = new PageReference(requestoAuthURL); return pageRef; } public void doGetAccessToken(){ Http http = new Http(); HttpRequest httpReq = new HttpRequest(); HttpResponse httpRes = new HttpResponse(); String requestTokenBody = 'code='+authCodeFromURL+'&grant_type=authorization_code'+ '&client_id='+consumerKey+'&client_secret='+consumerSecret+ '&redirect_uri='+redirect_URI; String errorMessage = ''; System.debug('#### authCodeFromURL '+authCodeFromURL); System.debug('#### requestTokenBody '+requestTokenBody); httpReq.setMethod('POST'); httpReq.setEndpoint(accessToken_Endpoint); httpReq.setHeader('Content-Type', 'application/x-www-form-urlencoded'); httpReq.setBody(requestTokenBody); try{ httpRes = http.send(httpReq); if(httpRes.getStatusCode() == 200){ Map<String,object> TokenInfo = (Map<String,object>)JSON.deserializeUntyped(httpRes.getBody()); LinkedIn_Information__c linkedlnInfo = new LinkedIn_Information__c(); linkedlnInfo.Access_Token__c = String.valueOf(TokenInfo.get('access_token')); linkedlnInfo.Expires_In_Seconds__c = Double.valueOf(TokenInfo.get('expires_in')); linkedlnInfo.Name ='LinkedlnInfo'; if(linkedlnInfoList!=null && linkedlnInfoList.size() > 0){ linkedlnInfo.Id = linkedlnInfoList[0].Id; } ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM, 'Congrattzzzzz….. You have done successfull Integration with Linkedln')); upsert linkedlnInfo; }else{ errorMessage = 'Unexpected Error while communicating with LinkedIn API. ' +'Status '+httpRes.getStatus()+' and Status Code '+httpRes.getStatuscode(); ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, errorMessage)); } }catch(System.Exception e){ System.debug('#### Exception Excuted '+e.getStackTraceString()+' '+e.getMessage()); if(String.valueOf(e.getMessage()).startsWith('Unauthorized endpoint')){ errorMessage = 'Unauthorize endpoint: An Administer must go to Setup -> Administer -> Security Control ->' +' Remote Site Setting and add '+' '+ accessToken_Endpoint +' Endpoint'; ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, errorMessage)); }else{ errorMessage = 'Unexpected Error while communicating with LinkedIn API. ' +'Status '+httpRes.getStatus()+' and Status Code '+httpRes.getStatuscode(); ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, errorMessage)); } } } public void doFetchBasicInfo(){ String errorMessage =''; Http http = new Http(); HttpRequest httpReq = new HttpRequest(); HttpResponse httpRes = new HttpResponse(); List<LinkedIn_Information__c> linkedlnInfoListNew = [Select Id, Name,Access_Token__c,Expires_In_Seconds__c From LinkedIn_Information__c Where Name='LinkedlnInfo']; httpReq.SetMethod('GET'); httpReq.setEndpoint('https://api.linkedin.com/v2/me&#39;); httpReq.setHeader('Authorization', 'Bearer '+linkedlnInfoListNew[0].Access_Token__c); httpReq.setHeader('Content-Type', 'application/json'); try{ httpRes = http.send(httpReq); if(httpRes.getStatusCode() == 200){ System.debug('#### httpRes.getBody() '+httpRes.getBody()); Map<String,object> TokenInfo = (Map<String,object>)JSON.deserializeUntyped(httpRes.getBody()); String firstName = String.valueOf(TokenInfo.get('firstName')); String lastName = String.valueOf(TokenInfo.get('lastName')); String headline = String.valueOf(TokenInfo.get('profilePicture')); String personURN = String.valueOf(TokenInfo.get('ID')); BasicInfo = firstName +' ' + lastName +' '+headline+' ' +personURN; }else{ errorMessage = 'Unexpected Error while communicating with LinkedIn API. ' +'Status '+httpRes.getStatus()+' and Status Code '+httpRes.getStatuscode(); ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, errorMessage)); } }catch(System.Exception e){ System.debug('#### Exception Excuted '+e.getStackTraceString()+' '+e.getMessage()); if(String.valueOf(e.getMessage()).startsWith('Unauthorized endpoint')){ errorMessage = 'Unauthorize endpoint: An Administer must go to Setup -> Administer -> Security Control ->' +' Remote Site Setting and add '+' '+ 'https://api.linkedin.com/ '+' Endpoint'; ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, errorMessage)); }else{ errorMessage = 'Unexpected Error while communicating with LinkedIn API. ' +'Status '+httpRes.getStatus()+' and Status Code '+httpRes.getStatuscode(); ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, errorMessage)); } } } public void doSharePostOnLinkedIn(){ String errorMessage =''; Http http = new Http(); HttpRequest httpReq = new HttpRequest(); HttpResponse httpRes = new HttpResponse(); List<LinkedIn_Information__c> linkedlnInfoListNew = [Select Id, Name,Access_Token__c,Expires_In_Seconds__c From LinkedIn_Information__c Where Name='LinkedlnInfo']; httpReq.SetMethod('POST'); httpReq.setEndpoint('https://api.linkedin.com/v2/ugcPosts&#39;); httpReq.setHeader('Authorization', 'Bearer '+linkedlnInfoListNew[0].Access_Token__c); httpReq.setHeader('Content-Type', 'application/json'); httpReq.setHeader('x-li-format' , 'json'); httpReq.setHeader('X-Restli-Protocol-Version', '2.0.0'); String requestBody = '{'+ '"author": "urn:li:person:JFazRB41z1",'+ '"lifecycleState": "PUBLISHED",'+ '"specificContent": {'+ '"com.linkedin.ugc.ShareContent": {'+ '"shareCommentary": {'+ '"text": "Learning more about LinkedIn by reading the LinkedIn Blog!"'+ '},'+ '"shareMediaCategory": "ARTICLE",'+ '"media": ['+ '{'+ '"status": "READY",'+ '"description": {'+ '"text": "Official LinkedIn Blog – Your source for insights and information about LinkedIn."'+ '},'+ '"originalUrl": "https://blog.linkedin.com/&quot;,'+ '"title": {'+ '"text": "Official LinkedIn Blog"'+ '}'+ '}'+ ']'+ '}'+ '},'+ '"visibility": {'+ '"com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC"'+ '}'+ '}'; httpReq.setBody(requestBody); try{ httpRes = http.send(httpReq); if(httpRes.getStatusCode() == 200 || httpRes.getStatusCode() == 201){ sharedInformation = requestBody; ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM, 'Post has been shared successfully!!')); //Map<String,object> sharedPostInformaionMap = (Map<String,object>)JSON.deserializeUntyped(httpRes.getBody()); //urlToSharedPost = 'https://'+(String)sharedPostInformaionMap.get('updateUrl&#39;); }else{ errorMessage = 'Unexpected Error while communicating with LinkedIn API. ' +'Status '+httpRes.getStatus()+' and Status Code '+httpRes.getStatuscode(); ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, errorMessage)); } }catch(System.Exception e){ System.debug('#### Exception Excuted '+e.getStackTraceString()+' '+e.getMessage()); if(String.valueOf(e.getMessage()).startsWith('Unauthorized endpoint')){ errorMessage = 'Unauthorize endpoint: An Administer must go to Setup -> Administer -> Security Control ->' +' Remote Site Setting and add '+' '+ 'https://api.linkedin.com/ '+' Endpoint'; ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, errorMessage)); }else{ errorMessage = 'Unexpected Error while communicating with LinkedIn API. ' +'Status '+httpRes.getStatus()+' and Status Code '+httpRes.getStatuscode(); ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, errorMessage)); } } } } view raw LinkedlnoAuthController.java hosted with ❤ by GitHub Thanks, SFDCPanther LikeLike
  9. ghodasara divya May 1, 2019 / 10:36 am

    I can try ‘https://api.linkedin.com/v1/people/~/shares?format=json’ this endpoint but throw an error with 410 status code so i will change API with ‘ https://api.linkedin.com/v2/me‘ please help me…

    Like

      • ghodasara divya May 2, 2019 / 6:59 am

        I will try Field Selections with its API But it’s through error like ‘Not enough permissions to access: GET /people/(id: My Client Id)’… The issue in permission for my LinkedIn developer account. How can i get this permission for mine account?
        What can I do? Please help me.

        Liked by 1 person

      • Amit Singh May 2, 2019 / 7:10 am

        Hey,

        Have you created the Developer LinkedIn account and Also, created a Connected Application. Be sure that you have setup everything correct with Connected app and Call back URL

        Liked by 1 person

      • Amit Singh May 2, 2019 / 7:51 am

        Have you followed all the steps carefully? Each and Every detail are there in the Post. See below Image

        LinkedIn Connect App

        Thanks,
        Amit

        Like

      • ghodasara divya May 2, 2019 / 8:38 am

        Thanks for this link.But i have only three permission r_emailaddress,r_liteprofile,w_member_social. So I guess problem if there.

        Like

      • ghodasara divya May 2, 2019 / 10:32 am

        But I have share permission this w_member_social. I show the document and share post required only w_member_social permission. I don’t know, where I am wrong.

        Like

      • Amit Singh May 2, 2019 / 10:37 am

        Hi,

        Giving Permission at Connected Application is not enough you need to add that permission as a scope parameter while Authenticating the application. Make Sure that you are passing below permissions
        r_basicprofile r_emailaddress
        r_liteprofile
        w_share
        rw_company_admin
        w_member_social

        Like

      • ghodasara divya May 2, 2019 / 10:49 am

        I think w_share permission required for post share. But my knowledge w_share is old permission and w_share replace with w_member_social new permission.

        And I can send a request for a new Marketing Developer Platform product in my LinkedIn application but it is pending for review.

        Thanks for helping me.

        Like

      • Amit Singh May 2, 2019 / 10:52 am

        No. That is the required permission to share the content. The permission that you are using is for company accounts.

        Like

      • ghodasara divya May 2, 2019 / 11:00 am

        Oh! you are right.so I can’t use this API and can’t handle in Salesforce. Linkedin account
        not permission for that.

        Liked by 1 person

      • ghodasaradivya May 7, 2019 / 6:08 am

        Hey Amit,
        I have tried to get LinkedIn post in visualforce page. But I don’t know how many permissions are required. Please Help me.

        Like

      • Amit Singh May 7, 2019 / 12:05 pm

        Hi,

        You need to check the LinkedIn API for the same.

        Like

      • ghodasaradivya May 7, 2019 / 12:28 pm

        I was referred documentation but I have not a correct answer. I found get API for post not available in the documentation. So I will get post information or not.

        Like

      • Amit Singh May 7, 2019 / 2:18 pm

        Hi,

        everything should be there in the document. If it is not there then probably either you need to connect to LinkedIn Support or it is not supported to get all the posts

        Like

      • ghodasaradivya May 21, 2019 / 7:04 am

        Hi Amit,
        1. I have created two fields for store username and password in LinkedIn Information object.
        2. Now When authentication request I have set email address and password value from Linkedin
        Information field user name and password.
        3.Like:-
        Email Address:- Username Field
        Password:- Password field

        Is this possible?

        Like

      • Amit Singh May 21, 2019 / 7:08 am

        If you are talking about storing the username and password then it is not possible.

        Like

      • ghodasaradivya May 21, 2019 / 7:20 am

        Already I have store username password in the object field. When I have a request for authentication code then open the login page I have set object field value in Email and password value.

        Like

  10. Prashant February 15, 2019 / 8:11 am

    HI Amit,
    Thanks for the awesome block.
    I have one question can we find all the contacts present on LinkedIn by matching the first name and last name.

    Like

    • Amit Singh February 17, 2019 / 7:40 am

      I am not sure but You can explore the API and see if we can. I will implement the same

      Like

      • Zulfi April 4, 2019 / 11:05 am

        Hi Amit,

        I am getting 401 error after sucessfull authorization, when I click on basic info button, got 401 error.
        Can you please help me.

        Like

    • zulfi April 4, 2019 / 7:15 am

      Hi sir,
      I am getting error, on 25th line
      Select Id, Name, Access_Token__c, Expires_In_Seconds__c
      ^ERROR at Row:1:Column:18
      No such column ‘Access_Token__c’ on entity ‘LinkedIn_Information__c’. If you are attempting to use a custom field, be sure to append the ‘__c’ after the custom field name. Please reference your WSDL or the describe call for the appropriate names.

      63,.Variable does not exist: Access_Token__c 64.Variable does not exist: expire in seconds__c
      Same on 101, 105, 144, 148 line,
      Please help, it will be greatful

      Like

      • Amit Singh April 4, 2019 / 12:03 pm

        Hi, Did you created Access_Token__c Field on LinkedIn_Information__c Object?

        Like

    • ghodasara divya May 2, 2019 / 9:58 am

      I have permission for share post .when I can add post request but I face error ‘com.linkedin.publishing.util.common.ResponseException: Writers of type person are not authorized to modify UserGeneratedContent.’ 401 status code.

      Please help me what can I do?

      Like

      • Amit Singh May 2, 2019 / 10:09 am

        From the Error, I can say that the URL that you are hitting to share the Post is not correct. OR you have not authorized permission to share the post. Cross check the Connected App Settings

        Like

  11. Deepika October 7, 2018 / 5:06 am

    Hi Amit,

    I am getting below error while clicking on “Complete Authorization”:
    Error:
    Unexpected Error while communicating with LinkedIn API. Status Bad Request and Status Code 400

    Please help.

    Thanks,
    Deepika Ghose

    Like

  12. RUSSELL July 10, 2018 / 1:26 pm

    Hi – do you have example code that shows how you replace the references to the custom setting with a custom object name and fields please.

    Like

    • Amit Singh July 11, 2018 / 5:04 pm

      Hi Russel,

      No. I do not have but I will post them soon with Custom Object and Updated Code.

      Like

      • Amit Singh July 12, 2018 / 5:07 am

        Hi Russel,

        I have updated the code to Use the Custom Object and also added a new feature by which you can share the post to Linkedin from the Code.

        Let me know if you have queries

        Like

      • Kusuma May 8, 2019 / 6:26 pm

        Hi Amit,

        I am getting error on post.

        Error: unexpected error while communicating with the linkedin Api. Status un authorized and status code: 401

        When I run it in the postman the message I got is- Writers if type person are not authorized to modify UserGeneratedContent.

        Do I have to change anything in my connected app for permissions? I even added all the permussions in my scope.

        Any help is appreciated.

        Like

      • Amit Singh May 9, 2019 / 2:38 pm

        Hi,

        I have not worked on 3-legged Oauth. The blog is to authenticate using Oauth 2.O

        Like

  13. Akash April 15, 2018 / 1:22 pm

    Hi Amit,

    Thanks for providing such awesome implementation. It’s working perfect.!!

    I have below requirement. Please guide me:

    Req : I want to fetch my contact’s LinkedIn profile’s basic information (Salesforce standard contacts)

    Can you please guide me, what all changed needs to be done in your implementation to achieve my requirement?

    Any help would be highly appreciated

    Thanks a ton.!!

    Like

    • Amit Singh April 16, 2018 / 7:12 am

      Hi Akash,

      You want to fetch the Basic profile information of your Salesforce Contacts correct?
      To get the information of your contact your contact must authorize the application atleast once if contact has not authorized the linkedIn application then you can get their information.

      OR
      You wanted to fetch the LinkedIn contact information. If so refer below link for the same
      https://developer.linkedin.com/docs/guide/v2/people/connections-api#sample

      Like

      • Akash April 16, 2018 / 9:06 am

        Hi Amit,

        Thanks for the reply.!! Yes I want to fetch the basic profile information of my contact records.

        Can you please guide me below points :

        1) How my contacts should authorize the application? (If any code changes needed, please let me know)

        2) How to make the api callout request for specific contact’s LinkedIn’s basic profile information?

        Also, I’ve gone through the below link :

        https://developer.linkedin.com/support/faq

        It has been mentioned that LinkedIn doesn’t have any way to refresh the access token. So if the current access token get’s expired, is there any automated way we can update it in apex class?

        Thanks,
        Akash

        Like

      • Amit Singh April 16, 2018 / 10:23 am

        Akash,

        Put detail page button on the contact level which will open the LinkedIn authentication page and after you get the response from the LinkedIn save the response into the Custom Object.

        To refresh the access token Refer the given link
        https://developer.linkedin.com/docs/oauth2

        Like

  14. harish February 21, 2018 / 9:40 am

    when i click on get basic info I am getting this error…

    List index out of bounds: 0
    Error is in expression ‘{!doFetchBasicInfo}’ in component in page linkedlnoauth: Class.LinkedlnoAuthController.doFetchBasicInfo: line 100, column 1

    An unexpected error has occurred. Your development organization has been notified.

    when I click on complete authorization :
    Errors

    Access Token1: Access Token1: data value too large: AQUyRtz3_y2kJ7YnBVqXX8WEtKzUKw0hhH3_QTY1d0A_SCsIYiunij5HpNg5iu3FFIeyDTbOltLP3wp_1mpM2xmDais9F6IdFnU7Hwg0CFUKY6cF9BQh0dM1N2YbK2fztK4QSIEXVo8NdEHzop3elyt1GDcwXAzcWqa9qHr41MEWo1H6ndvctcxd84WKOScpcsxr11UBqVI3vJ2P3mC5QoVaT5LTaH3bK6cKmpAhmJgJ8k7RcyRvB9oVrb7913OMz_rDKP0qOm4SjB9JnJ1KR8nm9exQ_RRzc0nC4WHm6Nq8OgEScNYIXe55I_Ak-sUUPQbTh7IKFIxU1djAppLshNyEwO51Qg (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

    Like

    • Amit Singh February 21, 2018 / 12:53 pm

      Hi Harish,

      Need to check the below thing –
      1 – Access Token1: data value too large: Error because access token length is more than 255 Chars. As a solution Create a custom Object with the Exact Value and for Access and Refresh Token use TextArea Long instead of Text Field. And then use that custom Custom Object instead of LinkedIn_Token_Info__c Custom Setting

      Like

  15. hanitha February 7, 2018 / 5:19 am

    I have lot of job openings in my job opening object(salesforce) after completion of salesforce and linkedin authorization automatically whatever job postings are there in job opening object that all openings automatically should post in my linkedin

    pls Amith help me regarding this..how to do

    Like

    • Amit Singh February 7, 2018 / 7:32 am

      Hi Hanitha,

      For this we need to make some other API Call to post the Job form Salesforce to LinkedLn automaticlly. Let me do the test from my side and then I will post the code here in the comment Section.

      Like

    • Amit Singh February 7, 2018 / 11:21 am

      Hi Hanitha,

      I have checked and tested the same using the API Console of the LinkedIn and below are the details with the URL, header and body that you need to use while making callout from the salesforce.

      1- URL Endpoint – https://api.linkedin.com/v1/people/~/shares?format=json
      2 – Header – Content-Type : application/json
      3 – Header – x-li-format : json
      4 – Body in json format and below is sample body
      {
      “comment”: “Check out developer.linkedin.com!”,
      “content”: {
      “title”: “LinkedIn Developers Resources”,
      “description”: “Leverage LinkedIn’s APIs to maximize engagement”,
      “submitted-url”: “https://developer.linkedin.com”
      },
      “visibility”: {
      “code”: “anyone”
      }
      }

      In your case you need to develop the dynamic body and need to make the callout from the apex trigger with @future method.

      Hope this will be useful for you 🙂

      Regards,
      Amit

      Like

  16. hanitha February 7, 2018 / 5:13 am

    When i click on the complete authorization i am getting error:

    Error:
    Unauthorize endpoint: An Administer must go to Setup -> Administer -> Security Control -> Remote Site Setting and add https://www.linkedin.com/oauth/v2/accessToken Endpoint

    which access token end point i have to give

    Like

    • Amit Singh February 7, 2018 / 5:37 am

      Add -> “https://www.linkedin.com” url into the Remote Site Setting

      Like

  17. Ankit November 30, 2017 / 9:52 am

    Thanks for the solution, but I am facing issues during implementation of above example.

    I am using my developer (free) org, in this I am facing an issue while I am clicking on a “Complete Authorization” Button. facing this below issue:

    ———–
    Issue:
    15:06:47:863 USER_DEBUG [87]|DEBUG|#### Exception Excuted Class.selflearning.LinkedlnoAuthController.doGetAccessToken: line 76, column 1 Upsert failed. First exception on row 0; first error: STRING_TOO_LONG, Access Token: data value too large: AQXoXkOHB-jcDKI2Vehp3OJS2ajjzaPu-7CVLufzzqbxLPR0_R4sW3pSaJkZZVowRlpVjhptiUmV-Op-2bXDTa7CvBkcSwMBQxKpQQsWVw_FRPR97EsAbXvEIrJEamNfpOlyNAZZ0LdFwHHqyuFiUQqhIfbfH9NIK4GDbB2Xj46O4T_-_Z-pWM5cLjy2uwwGH0V2ldChwwJ0WgN7A7qAoLdgO2yC1zmBHQbKyRkNz1y5MWRQP8VWDYQvpp3Mu4_0DsyPijHY_VDuuxTmx30Tmhz1IKoJqVGtdL2GMcTgH4gt9pKz6i6oxC2ZDtWvmUaMldIxEaDJr_LzatOoqxRJ6b3Zk7TsVA (max length=255): [selflearning__Access_Token__c]

    ————-

    where field (selflearning__Access_Token__c) of custom setting is of text type with 255 max character.

    Have you any idea how to resolve this.

    Thanks in advance

    Like

    • Ankit November 30, 2017 / 11:24 am

      Thanks Amit Singh for the nice startUp. I did it

      Like

    • Amit Singh November 30, 2017 / 4:42 pm

      This issue is because that the value of Access Token is larger than 255 character. As an alternative create a custom object with the same attribute as custom setting and for access token create text area long field instead of Text and make the necessary changes into the code replace custom setting in the code.

      Like

      • Ankit December 5, 2017 / 6:28 am

        Hey Amit, thanks for reply.

        I did it by same logic on same day.

        Nice setup/plateform you are providing for learning.

        Keep it up. 🙂

        Like

Leave a comment