You need to sign in to do that
Don't have an account?

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) {
UserTriggerHandler.uploadPhoto(Trigger.new);
}
}
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) {
UserTriggerHandler.uploadPhoto(Trigger.new);
}
}