I'm trying to use ConnectApi.ChatterUsers.getUserBatch()
to migrate users' photos. However, the ConnectApi.User
object that I get only seems to have access, through its photo
property, to the ConnectApi.Photo.photoVersionId
value. However, when using ConnectApi.ChatterUsers.setPhoto()
I need to actually provide a fileId
, not a photoVersionId
.
My question is: Knowing the photoVersionId
, how do I get the fileId
?
Below is a sample anonymous Apex code block that illustrates what I'm trying to do. It will reproduce the same error I've described above.
Id fromUserId = '005j0000000Z1Lx';
Id toUserId = '005j0000000Zqt3';
for (ConnectApi.BatchResult eachResult :
ConnectApi.ChatterUsers.getUserBatch(
null, new List<Id> { fromUserId })) {
ConnectApi.User eachUser = (ConnectApi.User)eachResult.getResult();
ConnectApi.ChatterUsers.setPhoto(null, toUserId, eachUser.photo.photoVersionId, null);
}
Best Answer
BritishBoy above is correct -- so the only way I could find to access the User Photos is through the URL:
Note that there's a couple caveats with the method above: