Skip to content

Update a Users profile photo from a URL (e.g. from Google SKIM)

Notifications You must be signed in to change notification settings

st-sfdc/SF-ProfilePhoto

 
 

Repository files navigation

Implementation considerations for your UserPhotoHandler class and trigger

Please Note: I assume absolutely no responsibility for any of the code in this repository. Use at your own risk.

  1. Batch Handling: The trigger groups user records to process them in batches, reducing the number of queued jobs. It attempts to queue up to 49 users in each batch due to the Queueable governor limits.

  2. HTTP Callout Failures: The current design might fail if the provided photo URL is not accessible or returns an error. Consider adding more robust error handling or notifications for such cases.

  3. Content Version Storage: The solution saves each photo as a new ContentVersion. Over time, this could result in a lot of stored photos if users frequently update their profile photos. Regularly cleaning up old photos or reusing content versions could help manage storage.

  4. Trigger Logic: The trigger currently fires after insert and update on the User object. As your org grows and other processes get built around the User object, consider refactoring to ensure the trigger remains efficient and does not conflict with other operations.

  5. Concurrent Execution: If multiple operations (such as bulk updates) are done in quick succession, there's a potential risk of hitting Salesforce's concurrent long-running transaction limit.

  6. Testing with Real Image Data: The test class uses a mock response with a string representation of an image. For more accurate testing, consider using a real image Blob or mimicking a more realistic response body.

  7. Profile Photo Overwrite: If a user updates the SF_User_Profile_Photo__c field with the same URL, the photo will be downloaded and set again. Depending on the intended behavior, you might consider adding logic to avoid unnecessary overwrites.

  8. Governor Limits: Always monitor for potential governor limit issues. With multiple users triggering the logic simultaneously, there's the risk of hitting the maximum number of asynchronous jobs added to the queue.

  9. Photo File Type: The current implementation assumes a .jpg file type. If users provide URLs to images of other formats, this might cause discrepancies in how the image is handled and displayed.

  10. Permission Considerations: Ensure that all user profiles that will be updating their photos have the necessary permissions to create ContentVersion records and execute the logic.

  11. Regularly reviewing and optimizing the code will ensure that the solution remains effective and efficient as your Salesforce instance grows and changes.

About

Update a Users profile photo from a URL (e.g. from Google SKIM)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Apex 95.3%
  • JavaScript 3.5%
  • Shell 1.2%