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.
<template> | |
<div class="slds-p-around_medium c-bg"> | |
<template if:true={photoId}> | |
<img class="slds-align_absolute-center c-image-round" src={photoURL}></img> | |
</template> | |
<template if:false={photoId}> | |
<lightning-file-upload | |
label="It seems like you have not uploaded any photo till now. Please click on the Upload Files button." | |
name="fileUploader" | |
accept={acceptedFormats} | |
record-id={recordId} | |
onuploadfinished={handleUploadFinished} | |
> | |
</lightning-file-upload> | |
</template> | |
</div> | |
</template> |
import { LightningElement, wire, api } from 'lwc'; | |
import { ShowToastEvent } from 'lightning/platformShowToastEvent'; | |
import { getRecord, updateRecord } from 'lightning/uiRecordApi'; | |
import { refreshApex } from '@salesforce/apex'; | |
import ID_FIELD from '@salesforce/schema/Lead.Id'; | |
import PHOTO_ID_FIELD from '@salesforce/schema/Lead.Photo_Id__c'; | |
export default class LeadPhotoUploader extends LightningElement { | |
@api recordId; | |
lead; | |
photoId; | |
photoURL; | |
/* Load Lead.Photo_Id__c for displaying the photo */ | |
@wire(getRecord, { recordId: '$recordId', fields: [PHOTO_ID_FIELD] }) | |
wiredRecord({ error, data }) { | |
if (error) { | |
let message = 'Unknown error'; | |
if (Array.isArray(error.body)) { | |
message = error.body.map(e => e.message).join(', '); | |
} else if (typeof error.body.message === 'string') { | |
message = error.body.message; | |
} | |
this.dispatchEvent( | |
new ShowToastEvent({ | |
title: 'Error loading information', | |
message, | |
variant: 'error', | |
}), | |
); | |
} else if (data) { | |
this.lead = data; | |
if (this.lead.fields.Photo_Id__c.value) { | |
this.photoId = this.lead.fields.Photo_Id__c.value; | |
this.photoURL = '/sfc/servlet.shepherd/version/download/' + this.photoId; | |
} | |
} | |
} | |
get acceptedFormats() { | |
return ['.png','.jpg','.jpeg']; | |
} | |
handleUploadFinished(event) { | |
// Get the list of uploaded files | |
const uploadedFiles = event.detail.files; | |
this.photoId = uploadedFiles[0].contentVersionId; | |
this.updateLead(this.photoId); | |
this.photoURL = '/sfc/servlet.shepherd/version/download/' + this.photoId; | |
} | |
updateLead(photoId) { | |
const fields = {}; | |
fields[ID_FIELD.fieldApiName] = this.recordId; | |
fields[PHOTO_ID_FIELD.fieldApiName] = photoId; | |
const recordInput = { fields }; | |
updateRecord(recordInput) | |
.then(() => { | |
// Display fresh data in the form | |
return refreshApex(this.lead); | |
}) | |
.catch(error => { | |
this.dispatchEvent( | |
new ShowToastEvent({ | |
title: 'Error updating photo information on lead record', | |
message: error.body.message, | |
variant: 'error' | |
}) | |
); | |
}); | |
} | |
} |
.c-bg { | |
background-color: rgb(242, 242, 242); | |
} | |
.c-image-round { | |
border-radius: 50%; | |
height: 70px; | |
width: 70px; | |
} |
Great one!
ReplyDeleteThat 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
I had no idea what a blog was or how to start one
ReplyDeleteLMS Education
New LMS
Thank you for taking the time to write such an informative post. Your blog is not only informative, but it is also very creative.
ReplyDeleteweb application development services
Nice Blog. Thanks for sharing information about salesforce consultant.
ReplyDelete