If you have a product record / a training course / a booking link or any record which you have an external like want to share to social media (Facebook, Twitter, LinkedIn), This simple solution perhaps is for you. In this article, we are going to create an LWC which can allow you to share any record to LinkedIn, as soon as the object has a “Share_URL__c” field. Also, you can clone it to create LWCs to share to other platforms.

  • Create a Share_URL__c field in target object. This can be a string / url / formula for you need.
  • Create an Apex helper to query the Share_URL__c field of any given object:
//ShareSocialHelper to query Share_URL__C field of any object by ID
public with sharing class ShareSocialHelper {
    public static final string fieldAPI = 'Share_url__c';
    public static string getShareUrlField(string recordId){
        //not an ID return '';
        if(!(recordId instanceOf Id)) return '';
        Id recId = Id.valueOf(recordId);

        //Get Describes Object Result with Id 
        Schema.DescribeSObjectResult od = recId.getSObjectType().getDescribe();
        string objectAPI = od.getName();

        //Get all sObjectField
        Map<string,Schema.SObjectField> mfields = od.fields.getMap();
            return '';

        //get specific field with field API 
        Schema.SObjectField field = od.fields.getMap().get(fieldAPI);

        string query = generateSOQL(fieldAPI,objectAPI,recId);
        List<SObject> sObj = Database.query(query);
        if(sObj.isEmpty()) return '';
        return (String) sObj.get(0).get(fieldAPI);

	private static string generateSOQL(String fieldName, string objectAPI,string recId){
		string rtn = 'select '+fieldName+'  from '+ objectAPI + ' where Id=\''+recId+'\'';
		return rtn;

  • Create a shareLinked LWC to allow it to be added to any record page. I used an apex helper to query record because I want it can be placed in any record page.
    <lightning-card title="Share To Linkedin">
        <span onclick={handleClick}>
            <img src={linkedLogo}>
import { LightningElement,api } from 'lwc';
import socialIcons from '@salesforce/resourceUrl/socialIcons';
import getShareUrl from '@salesforce/apex/ShareSocialHelper.getShareUrlField';
import {convertObject2Params} from 'c/utils'
let LINKEDIN_SHARE_ARTICLE = 'https://linkedin.com/shareArticle'

export default class ShareLinked extends LightningElement {
    @api recordId;
    sharedUrl = 'https://leeseifer.wordpress.com';
    linkedLogo = socialIcons +'/icons8-linkedin-96.png';
            this.sharedUrl = result;
            console.log('error ', error);
        window.open(LINKEDIN_SHARE_ARTICLE + 


<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
//Utils component
const convertObject2Params = (obj) => {
    return ('?' +
        .filter(key => !! obj[key])
        .map(key => `${key}=${encodeURIComponent(obj[key])}`)


export {
  • Add the component to Lightning Page Layout and Test.