function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Komal DhimanKomal Dhiman 

UserTrigger caused an unexpected exception: UserTrigger: execution of AfterInsert caused by: System.HandledException: DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): Photo, original object: User

Hi everyone
I am writing a trigger on after insert.
This trigger will set the photo of user that is inserted.
But i am getting this error on creation of user.
My trigger handler class is
public without sharing class UserTriggerHandler{
     public static void uploadPhoto(List<User> userList){
        Document document=[SELECT Id,Body,DeveloperName FROM Document WHERE Document.DeveloperName='User_Logo'];
        for(User user:userList){
            Blob b= document.Body;
            String communityId = null;
            ConnectApi.Photo photo = ConnectApi.UserProfiles.setPhoto(communityId, user.Id, new ConnectApi.BinaryInput(b, 'image/jpg', 'userImage.jpg'));

My trigger is
trigger UserTrigger on User (after insert) {
    if (Trigger.isAfter && Trigger.isInsert) {