Photo Uploader for Leads

 A very common requirement across organizations that use Salesforce is the ability to upload a profile picture for the leads and contacts they are dealing with. Unfortunately, there is no OOTB feature provided by Salesforce which meets this requirement. There are multiple ideas on the trailblazer community where people have asked for this feature. Also, there are a few apps available on AppExchange which allow you to upload a profile picture, but those apps come with their own branding, and the majority of the organizations are not comfortable using such apps.

Considering all the above points, I have created an unmanaged package named "Lead Photo Uploader" which allows you to upload a profile picture against a lead record. Since this is an unmanaged package, you will have the access to the codebase and you can also modify it as per your needs. The same concept can be extended to other objects such as Contacts or other custom objects in your org. Here is a short video that shows a sneak peek of the application:

The unmanaged package contains below listed components:

  • An LWC component bundle called "Lead Photo Uploader" - This component needs to be added to the Lead record page
  • A custom field named "Lead.Photo_Id__c" - This field will be added to the Lead object once you install the package. This field is used to store the content version id.
Let's have a look at the code and try to understand the important functionalities:
leadPhotoUploader.html
The HTML code is pretty simple. The first section is displayed if the Photo_Id__c field on the Lead object has a value populated in it. If the value is present, the content version id is rendered using an image tag. The second section is displayed if the Photo_Id__c field on the Lead object is null. If the value is null, an option to upload the photo is presented to the user. Here, I have used the lightning-file-upload LWC component to upload the photo.
leadPhotoUploader.js
Here we make use of the getRecord wire adaptor to get the value of Photo_Id__c field. If the value is not null, the image is shown in the HTML. If the value is null, then an option to upload the photo is presented to the user. When the user clicks on Upload Files button, the handleUploadFinished method is called. The beauty of the lightning-file-upload method is that it automatically uploads the file into the Document object and returns you the documentId and the contentVersionId. We use this content version id in the image tag to display the profile picture. Also, I have used the updateRecord wire adaptor here to update the Photo_Id__c field with the contentVersionId so that the next time you open this lead record, the component will know which image it needs to show as a profile picture.
leadPhotoUploader.css
To display the profile picture in a circular format, I have applied the border-radius as 50% to the image tag.
If you want to try this functionality in your org, you just need to install the package and add the "Lead Photo Uploader" component in the Lead Record Page and you are good to go. If you have any feedback, please post it in the comments section.


Comments

  1. Great one!
    That said you can find free components on the AppExchange which does that WITHOUT ANY EXTRA BRANDING (and no size limitations) such as the SharinPix Free Components where you have :
    - an Image Component to render a single image from a URL or a content ID
    - an Images component to upload multiple images to a record with many options

    And if ever you need even more, you can also rely on SharinPix paid app on the AppExchange to get advanced features for that specific Use Case such as :
    - Automatic face detection to resize around the face
    - Crop after upload option
    - Render in a field so it could be available for Views, Reports and more!

    Here are the links to the AppExchange for those :
    http://bit.ly/SharinPixAppExchange for the paid App
    http://bit.ly/SharinPixFreeComp for the free components

    ReplyDelete
  2. I had no idea what a blog was or how to start one
    LMS Education
    New LMS

    ReplyDelete
  3. Thank you for taking the time to write such an informative post. Your blog is not only informative, but it is also very creative.
    web application development services

    ReplyDelete
  4. Nice Blog. Thanks for sharing information about salesforce consultant.

    ReplyDelete

Post a Comment

Popular posts from this blog

Salesforce Lightning: Countdown timer

Salesforce Hacks: System.LimitException: Too many queueable jobs added to the queue: 2

Building an Org Role Hierarchy component in LWC