I have a URL which is a PNG file which is hosted on external cloud and I would like to create a new file with this image in my salesforce opportunity object as a file. Could anyone point me on how to do this ? Thanks in advance
ContentVersion contentVer = new ContentVersion(Title = 'Image',
ContentUrl = 'https://xxxxxxx'
);
insert contentVer;
ContentDocument contentDoc = [SELECT Id FROM ContentDocument WHERE Title = 'Image'];
ContentDocumentLink contentDocLink = new ContentDocumentLink();
contentDocLink.ContentDocumentId = contentDoc.Id;
contentDocLink.LinkedEntityId= '0061l00000LLtmgAAD';
contentDocLink.ShareType='V';
contentDocLink.Visibility='AllUsers';
insert contentDocLink;