I'm using this code to create a document and use it to get fullPhotoUrl field in a test class but I got the error : ConnectApiException :The file you uploaded doesn't appear to be a valid image could someone please help with this.

ContentVersion cv = new ContentVersion(
                Title = 'Test',
                PathOnClient = 'Test.jpg',
                VersionData = blob.valueof('Test Content Data'));
        insert cv;

        List<ContentDocument> documents = [SELECT Id, Title, LatestPublishedVersionId 
                                           FROM ContentDocument where LatestPublishedVersionId=:cv.id];

        ConnectApi.Photo photo = ConnectApi.UserProfiles.setPhoto(null, userId, documents[0].Id,null);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.